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:
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:
To use those values, select the status property and click on “Choice List” from the Property window to open the Choice List Dialog.
Go back to the Excel file you have, select the values and copy them to Clipboard
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.
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.
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
You select the new items and copy them
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.
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
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.
Right-click and select the Copy command from the context menu or press Ctrl+C.
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:
Amr Altahlawi, LightSwitch SDE