Choice List improvements (Amr Altahlawi)

One of the new LightSwitch features in the Visual Studio 2013 Preview is the ability to import a list of name/value pairs to the Choice List dialog from either a file or from another Choice List. This is useful when you have a long list of values that you need to add (for example: List of US states), in which you can simply copy and paste them to the Choice List.

This feature will allow you to:

    • Copy a list of name/value pairs from an Excel file or a text file to the Clipboard and then paste them to the Choice List.
    • It only supports copying of single and double columns. If you copy more than 2 columns, only the first two will be copied and pasted.
    • The name/value pair should be tab delimited and the line should ends up with the new line character.
    • You can paste the values into the Choice List by either using the keyboard “Ctrl+V” or by using the Paste command from the context menu.

Now let’s start with some examples. Let’s say you are creating a simple application that stores sales orders. For every sales order, you need to track its status:

clip_image001[4]

You keep the list of options for this status property in an Excel file since it’s easier to enter, edit and sort in Excel:

clip_image002[4]

To use those values, select the status property and click on “Choice List” from the Property window to open the Choice List Dialog.

clip_image003[4]

clip_image004[4]

Go back to the Excel file you have, select the values and copy them to Clipboard

clip_image005[4]

Now go back to the Choice List dialog and right-click on the edge of the grid and select the Paste command to paste the values. Make sure not to right-click on the cell, otherwise you’ll get the context menu of the cell which is different than the context menu of the Choice List grid.

clip_image006[4]

clip_image007[4]

As you can see LightSwitch treated the first column that was copied from Excel as the value for the Value column, and the second column from Excel as the value for the Display Name column.

Tip: Your copied list doesn’t have to provide all the values for the Display Name. If the 2nd column is blank, the Choice List will use the Value for the Display Name.

Press Ok and Hit F5 and there you have it.

clip_image009[4]

Now after you test the application you realized that you still missing some values and you need to add them to the list, what should you do? You could simply copy the values from the Excel file and paste them to the Choice List in the position you want. Here is the list from Excel file with the new items

clip_image010[4]

You select the new items and copy them

clip_image011[4]

You go to the Choice List diagram and highlight the row you want to insert the new items after. Paste the values from Clipboard by either choosing the Paste command from the context menu or by pressing Ctrl+V.

clip_image012[4]

clip_image013[4]

If you want to insert the new items in another position (Before the “Paid” item), you simply right-click on the edge of the grid next to the Paid item and select Paste command from the context menu

clip_image014[4]

clip_image015[4]

Now let’s say that you have a new requirement that is to add a status for the Sales Order Items too, and the status values are same as the status values for the Sales Order Header entity except for few items. What should you do? You could simply select the items from the existing Choice List that you have and copy them to the Choice List of the order details.

Here is how you can do it:

Open the Choice List dialog that you created before and select the items you want.

clip_image016[4]

Right-click and select the Copy command from the context menu or press Ctrl+C.

clip_image017[4]

Go to the other Choice List and you want to copy the items too and right-click the mouse and select the Paste command from the context menu:

clip_image019[4]

clip_image020[4]

So that was one of the helpful features you could do in Visual Studio 2013 Preview. Let us know on the forums how you’re using this feature or if you run into any problems.

Thanks,

Amr Altahlawi, LightSwitch SDE

Technorati Tags: VS2013,Choice List