Skip to main content

Lightswitch - HTMLclient

It has been to long since my last post. As everyone else I have had trouble with finding time to blog. 

Recently I have been playing with the new Visual Studio Lightswitch (you can get update 2 here: Why is it so cool, because it is pure HTML5 and will run in any modern browser being Mac, PC, tablet, IPAD, Iphone, Androd etc. 

There are some nice posts out there to get you started, however I was looking for a way to on-the-fly created dropdown lists boxes (what we call ChoiceList in Lightswitch). I found this blogpost about someone else wondering about the same thing:

That guy Huy is pretty awesome (he as an answer to almost every question), and I felt all hope was lost when he stated that it was not possible. Reading further down, I noticed this guy pointing me in the right direction. Apparently the choice "field" has a variable for holding the choiceItems. 

Off we go then. Lets create a local data item on an edit screen and create a dummy item in the choice list:

Then add the data item to the edit list:

Run the application to see that our choice list is rendered:

Yes, it is working fine. Now let's write a little javascript to create the content in the dropdown:

First open the code editor:

var myDropdown;
var myValues = new Array();
myapp.AddEdittblProduct.created = function (screen) {
    // Write code here.
    choice = screen.findContentItem("CodeChoice");
    myValues[0] = { "value": 1, "stringValue": "Dropitem1" };
    myValues[1] = { "value": 2, "stringValue": "Dropitem2" };
    myValues[2] = { "value": "Dropitem3", "stringValue": "Dropitem3" };
    myValues[3] = { "value": "Dropitem3", "stringValue": "Dropitem4" };
    choice.choiceList = myValues;

Lets run it again and see what we have:

There you go. You can now add items to a dropdown in code.

I have no idea if this is a supported solution, the Lightswitch team will have to comment on that. In the mean time, please use it at your own risk. 

NOTE! If you skip adding an dummy item to the choicelist, this metod will not work!!



  1. Very nice, but how do you bind your Choice list back to your data?

  2. Does anyone know how do we bind dropdown list from a view ?
    And once user select data from dropdown, how to we assign back to Database.

  3. Is there an example like this that will work with VS 2015?

  4. Is there an example for dynamically populating choice lists in the LightSwitch HTML client using VS 2015?

    1. Hi, not that I know of. Lightswitch is currently in the dark. Last blogpost is from 2014 and I cannot find any news about it since. Someone mentioned something about a patent lawsuit against Microsoft. Hopefully we will hear something about in at Ignite 2016, however chances are slim to say the least!




Post a Comment

Popular posts from this blog

Developing PowerShell modules for REST APIs – Part1

Over the years I have developed different PowerShell modules for different web APIs. I thought it would be a good idea to write a 2 series post about how you could go about to do this. This will be a 2 part blog series where we will run through the entire process of building a module for a REST API. I will try my best to keep this as simple as possible and leave more advanced stuff for a follow up post if the interest is there.What you needDepending on your experience with source control and PowerShell in general, you might want to use GIT or some other software repro for the code. In addition we are going to create a test REST API using the splendid UniversalDashboard PowerShell module created by Adam Driscoll. It is available on the PowershellGallery. Other prerequisites are built-in to Powershell. I will assume that you will be following along using at least PowerShell version 5 or greater.
What is HTTP metods for REST API.The primary or most common HTTP verbs used are POST, GET, PU…

Serialize data with PowerShell

Currently I am working on a big new module. In this module, I need to persist data to disk and reprocess them at some point even if the module/PowerShell session was closed. I needed to serialize objects and save them to disk. It needed to be very efficient to be able to support a high volume of objects. Hence I decided to turn this serializer into a module called HashData.

Other Serializing methods

In PowerShell we have several possibilities to serialize objects. There are two cmdlets you can use which are built in:
Both are excellent options if you do not care about the size of the file. In my case I needed something lean and mean in terms of the size on disk for the serialized object. Lets do some tests to compare the different types:


You might be curious why I do not use the Export-CliXML cmdlet and just use the [System.Management.Automation.PSSerializer]::Serialize static method. The static method will generate the same xml, however we …

Developing PowerShell modules for REST APIs – Part2

This is part 2 of the REST API blogpost. In part1 we successfully setup two REST API endpoints using the UniversalDashboard PowerShell module. In this part we are going to create a simple module that support some CRUD operation against our API. As we are trying to keep things as simple as possible, we will not use any fancy framework (like Plaster) to build our module. We are also going to skip a very important step you should familiarize yourself with, Pester tests. Lets get to it.

The moduleWe will build a module called FilesAPI. The module folder will look like this:

In the functions folder I have already added the 2 helper functions from part 1, Get-AuthorizationHeader and ConvertTo-Base64. The other folders are just placeholders for important stuff like classes, private functions that you do not want to make available for the module consumer and tests for Pester tests. For such a small module that we are going to create, one could argue that it is much easier to just add the functi…