Choice List improvements (Amr Altahlawi)

Choice List improvements (Amr Altahlawi)

  • Comments 11

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

Leave a Comment
  • Please add 6 and 6 and type the answer here:
  • Post
  • Please, create the custom control grid color and custom control upload/download files.

  • Ricardo - thanks for the feedback!  We'll definitely take this into consideration for future releases.  If you have any other feedback just post to the forums ( social.msdn.microsoft.com/.../home ) or send me mail directly (peter.hauge @ microsoft.com ).  Thanks!

  • It would be interesting in the code behind an enumerator was created with items from the list of choices.

  • Who can tell how to fill in the Choice List of tables MS SQL?

  • Hi Victor,

    Thanks for the post. This is something we've considered. Unfortunately, it hasn't yet made our priority list. You can create a request on UserVoice connect.microsoft.com/lightswitch which we regularly review for suggestions.

    SlotDB,

    Are you looking for the choice list to be populated with the list of tables in the database?

    Thanks,

    Steve

  • Стив Ласкер-MS - Yes

  • a table would be preferable (client rather than programmer can maintain) and also adjust for local preferences).

    and if this choice list can do multi select it would just be a dream come true.

    ie:   pack;ship   is result of selecting both options.

  • I am with SlotDB!  It seems odd that ChoiceList cannot easily be bound to data from a table in SQL.

    Then the user can add something to table via an Add/Ediyt scrren and the list is updated dynamically for them.

    I do realize there is ways around this, however LightSwitch is supposed to ease development.... so...lets make it easy!?

  • @Bret, @SlotDB -- You can DEFINITELY define a lookup table, set up a relation, and then (boom) LS will automatically generate a modal pick list for your screen that is completely data driven. Choice lists are good for STATIC values (i.e. Yes/No, Male/Female, etc). You definitely should use lookup tables in LightSwitch for dynamic choices. See: msdn.microsoft.com/.../ff961882.aspx

    Cheers,

    -Beth

  • Hi,

    I'm Munna Kumar Sah

    Thanks For share . Its very usefull for me because this Article instruct to step by step.

    Thanks

  • Thanks a lot for above Tip.... it saved me loads of time.. absolutely loved it !!

Page 1 of 1 (11 items)