LightSwitch – Entering data using a ComboBox

Overview of Article

The following article describes how to add a ComboBox control onto a screen for the purpose of data entry. The example project uses the customer table from the previous post. The customer table is related to a ‘Town’ table, allowing us to select a town for any given customer.

Data

Create a table called Town with the following schema.

Town
ID Int32
TownName String

The Customer table from our previous post will be used for this example. In the table designer,  click on the ‘Add Relationship’ button and add a ‘one to many’ relationship between Town and Customer. The schema of the table will look like the table below.

Customer
ID Int32
Firstname String
Surname String
Town Town

image

Fig1 – Adding a relationship between customer and town

Adding the relationship as illustrated above is a key step to making this work. If you are working against  existing SQL Server tables outside the intrinsic ApplicationData database, it is important that relationships are properly set up at the SQL level. If relationships are not set up in SQL Server, it isn’t possible to open the screen in Fig1 to set the relationship at a LightSwitch level.

If it isn’t possible to set up relationships in SQL Server, you can use the ‘multiple datasource’ trick to get around this problem. More details can be found on this thread:

http://social.msdn.microsoft.com/Forums/en-US/lightswitchgeneral/thread/ed39324f-9e4c-449a-8703-80a964c5d8e3

Screens

Create an ‘Editable Grid Screen’ on the town table to allow you to enter some towns.

Now moving onto the Customer data entry screen with ‘Town’ dropdown…

  1. Create a new screen based upon the ‘New Data Screen’ template. In the ‘Screen Data’ dropdown, choose ‘Customer’.  
  2. By default, a ‘Two Row’ screen is created and ‘Town’ will appear as ‘Modal Window Picker’. Click the downward arrow next to Modal Window Picker to change the control to a ‘ComboBox’.

    image
    Fig 2 – Change from ‘Modal Window Picker’ to ‘ComboBox’

Conclusion

Run the project and add some towns using the Editable grid screen. Open the ‘CreateNewCustomer’ form and create a new customer. A ComboBox will appear allowing you to select a town for your new customer.

 

Technorati Tags: ,,
Advertisements

About dotnettim

Tim Leung is a Microsoft .Net / SQL Server developer based in England.
This entry was posted in LightSwitch, Uncategorised. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s