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
- Visual studio 2010 is installed on your machine.
- Visual Studio 2010 service pack 1 is installed on your machine.
- Microsoft Visual Studio Light switch 2011 is installed on your machine.
- How to create lightswitch using visual studio?
- How to add new screen in lightswitch project?
- How to add controls in lightswitch screen?
Steps Involved
- Create any screen (without selecting Screen Data option)
- Add Code to eliminate nullable value of checkbox
Step 1.: Create Any Screen (Without Selecting Screen Data Option)
- Create a new lightswitch project
- Add a new screen
Click to Enlarge
- Once the screen is created click on ‘Add Data Item’ in the screen
- Uncheck ‘IsRequired’
- Provide a name which in this case is ‘Chk Test’
Click to Enlarge
- Once added drag data item only to screen
- Run the application
- Nullable(unknown with minus sign)
- False(blank)
- True (with checked sign)
Click to Enlarge
Step 2. Add Code To Eliminate Nullable Value Of Checkbox
Click to Enlarge
- Click on ‘ChkTest’ as shown above
- Write code for the ‘ChkTest_Changed’ property as shown below:
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;
}
}
}
- 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.
Click to Enlarge