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: http://www.microsoft.com/en-us/download/details.aspx?id=38188). 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:

http://www.datazx.cn/Fv7p5a/6x-DE/y10q2an129q/2q7xs6/6mdggtxi-id9i-f4ij-s8ms-i94bt9tfcjg423rsdfd.html


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!!

Cya


Comments

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

    ReplyDelete
  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.

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

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

    ReplyDelete
    Replies
    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!

      Cheers

      Tore

      Delete

Post a Comment

Popular posts from this blog

Monitoring Orchestrator runbook events from Operations Manager

Today I will follow up on my colleague’s post Mr ITblog (Knut Huglen) about monitoring Orchestrator Runbook events.  He has build a nice double up SNMP loopback feature that does self monitoring in Orchestrator resulting in entries written to a special Windows Eventlog. Now we need to raise alerts in SCOM when one of his runbooks fails or sends a platform event, who knows there could be trouble lurking in his paradise.

We are not going to do anything fancy, however these are the steps we will be focusing on today:
Create a Management Pack for our customizations Create rules that collects the events from the orchestrator serverOff we go then and fire up the SCOM console and a powershell window. First we create a MP, I am going to use powershell to do this, however you may use the SCOM console as well (Administration – ManagementPacks – Action: Create Management Pack):



Import the Management Pack into SCOM and move on to the Authoring section in the SCOM console. Create a new rule:



Give the…

Powershell – Log like you mean it

How do you do logging in powershell? Why should you do logging? What should you log? Where do you put your log? How do you remove your log? How do you search your log? All important questions and how you answer then depends upon what your background is like and the preferences you have. This will be a 2 part blog post and this is part 1.


Why should you log?

Well it is not mandatory, however I have 2 reasons:
Help with debugging a script/module/functionSelf documenting script/module/function
Firstly; Do you know any program that does not contain any bugs? Working with IT for the last 2 decades, I cannot name one. When you create scripts/modules/functions, you will create bugs, that is where they live and try to make your life a living mess.

Secondly: Adding a little extra information to your logging will make them self documenting. Do you like writing documentation? Well I normally am not fond of it and use logging while debugging to get two birds with one stone.


What should you log?

Anyt…

Powershell - List information about your WIFI networks

This is just a quick post about this new function I have created. Basically this is a text-output to powershell object output function that uses netsh to query the WIFI information. This illustrates the importance of changing the authentication level on your WIFI-network. No matter if you use WEP/WPA/WPA2 your password is available in clear text in your profile.



Cheers

Tore