Filling AutoCompleteBox With Values in LightSwitch 2012

This article explains how to fill an AutoCompleteBox with values using a LightSwitch Application (Visual C#) in Visual Studio 2012.

The following is the procedure for filling in an AutoCompleteBox with values.

Step 1

Open the Solution Explorer.

sol explo.jpg

Step 2

In the Solution Explorer, right-click on the Server and choose the "Add Table" option.

add table.jpg

Step 3

In this way we will add two tables (one is an Employee table and another is an Item table). The tables appear as in the following.

Employee Table

Employee.jpg

Item Table

Items.jpg

Step 4

Here, we will not add any relationship between the two tables.

Step 5

In the Solution Explorer, right-click on the Screens and choose "Add Screen".

Add src.jpg

Step 6

The Add New Screen dialog box appears. Select the "New Data Screen" from the Screen Template, under screen information, choose "Employees" under screen data and provide some name to the Screen and click the "OK" button.

add new src dialog.jpg

Step 7

In the Menu bar click on "Add Data Item" button.

Add Data item.jpg

Step 8

The "Add Data Item" dialog box appears on the screen.

localprop.jpg
 
Step 9

Now we will delete the ItemsSet TextBox from the screen.

items set delete.jpg

Step 10


After deleting, the Solution Explorer will look as in the following:

app 1.jpg

Drag the prop node from the left side and put it onto the screen.

dragging.jpg

Step 11

In the menu bar, click on "Write Code"; a drop down list will appear and choose the "_Saving" method.

writecode.jpg

using System;

using System.Linq;

using System.IO;

using System.IO.IsolatedStorage;

using System.Collections.Generic;

using Microsoft.LightSwitch;

using Microsoft.LightSwitch.Framework.Client;

using Microsoft.LightSwitch.Presentation;

using Microsoft.LightSwitch.Presentation.Extensions;

 

namespace LightSwitchApplication

{

    public partial class CreateNewEmployee

    {

        partial void CreateNewEmployee_InitializeDataWorkspace(global::System.Collections.Generic.List<global::Microsoft.LightSwitch.IDataService> saveChangesTo)

        {

            // Write your code here.

            this.EmployeeProperty = new Employee();

        }

 

        partial void CreateNewEmployee_Saved()

        {

            // Write your code here.

            this.Close(false);

            Application.Current.ShowDefaultScreen(this.EmployeeProperty);

        }

 

        partial void CreateNewEmployee_Saving(ref bool handled)

        {

            // Write your code here.

            EmployeeProperty.ItemsSet = Prop.ItemName;

        }

    }

}

Step 12

Press F5 to run the application.

Here, an exception may occur since we are not establishing the relationship between the two tables. We can remove the exception by setting the choice list. For that we need to go to the property window and click on the "Choice List" hyperlink and add some items.


Similar Articles