Articles → LIGHT SWITCH 2011 → Convert Checkbox Nullable State To False In Lightswitch 2011

Convert Checkbox Nullable State To False In Lightswitch 2011






Objective Of This Tutorial





Prerequisites




  1. Visual studio 2010 is installed on your machine.
  2. Visual Studio 2010 service pack 1 is installed on your machine.
  3. Microsoft Visual Studio Light switch 2011 is installed on your machine.




  1. How to create lightswitch using visual studio?
  2. How to add new screen in lightswitch project?
  3. How to add controls in lightswitch screen?

Steps Involved




  1. Create any screen (without selecting Screen Data option)
  2. Add Code to eliminate nullable value of checkbox

Step 1.: Create Any Screen (Without Selecting Screen Data Option)




  1. Create a new lightswitch project
  2. Add a new screen
  3. Picture showing the popup for adding the Editable Grid Screen in the lightswitch application

    Click to Enlarge

  4. Once the screen is created click on ‘Add Data Item’ in the screen
  5. Uncheck ‘IsRequired’
  6. Provide a name which in this case is ‘Chk Test’
  7. Picture showing a window for adding the new data item in the lightswitch screen

    Click to Enlarge

  8. Once added drag data item only to screen
  9. Run the application


  1. Nullable(unknown with minus sign)
  2. False(blank)
  3. True (with checked sign)


Picture showing the different states of the checkbox in lightswitch screen

Click to Enlarge


Step 2. Add Code To Eliminate Nullable Value Of Checkbox


Picture showing adding the checkbox changed event

Click to Enlarge

  1. Click on ‘ChkTest’ as shown above
  2. Write code for the ‘ChkTest_Changed’ property as shown below:
  3. using System.Collections.Generic;
    using Microsoft.LightSwitch;
    namespace LightSwitchApplication {
      public partial class EditableGrid {
        partial void ChkTest_Changed() {
          if (ChkTest == null) ChkTest = false;
        }
    
        partial void EditableGrid_InitializeDataWorkspace(List < IDataService > saveChangesTo) {
          if (ChkTest == null) ChkTest = false;
        }
      }
    }


  4. As you can see above we have added the same code in initialize event because at the time when the screen gets loaded if the value of chkTest is null then it is important make it false.


Picture showing the checkbox nullable state is converted into false

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Monday, May 19, 2014

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250