Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Presenting a List of Choices in a LightSwitch Application

In this lesson, you’ll learn how to define an entity field so that users can choose a value from a list.

Sometimes an entity field represents data that must be restricted to a small set of valid values. For example, an Order Status field might have a fixed set of values: Pending Approval, Ready for Shipment, Shipped, and Backordered. To prevent a user from entering a status that isn't valid, you can present these four values as a choice list.

To create a choice list

  1. In Solution Explorer, open the shortcut menu for the Contacts.lsml node, and then choose Open.

    The Data Designer opens and displays the Contacts entity.

  2. In the Name column, replace the <Add Property> placeholder with ContactType, and then choose the Enter key.

  3. In the Type column, open the list, and then choose Integer.

  4. In the Required column, clear the check box.

  5. In the Properties window, choose the Choice List link.

    The Choice List dialog box opens.

  6. In the Choice List dialog box, enter the following values, and then choose the OK button.

    Value

    Display Name

    0

    Existing Customer

    1

    New Customer

    2

    Prospect

    The completed choice list

    When this field appears, users can open a list that contains the three Display Name values that you entered.

In this procedure, you created a choice list that offers three possible values. The choices appear at run time as a list that has three text values, but the data is still stored in its native data type, Integer. LightSwitch handles the conversion for you so that you don’t need to write any code.

You can also create choice lists in which the value and the display name are the same data type. For example, you might want to provide a fixed list of destination cities in a travel application. In this case, both the values that are presented to the user and the values that are stored in the data source would be of type String. If you use a choice list, users can't enter a city that isn't in the list.

In the next lesson, you’ll learn how to validate data entry.

Next Lesson: Validating Data in a LightSwitch Application

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.