LightSwitch Choice List Initial Default Value

How to define a starting value for a property in a screen?

We have an entity called “OT” and it has a property called “Status” is a String max length=2, there is a choice list:

  • “OK”, “Good” and
  • “BD”, “Bad”

When we enter the screen we want the property “Status” to have the value “OK” already entered.

Method 1. In the Entity. (Applies to all screens)

partial void OT_Created()
{
   Status = "OK";
}

Method 2. In the screen. (Applies only to that screen)

The screen is called “NewOT”.

partial void NewOT_InitializeDataWorkspace(global::System.Collections.Generic.List saveChangesTo)
{
   this.OTProperty = new OT();
   // our code to put a default value
   this.OTProperty.Status = "OK";
}

Pretty easy! Remember to put the line after “this.OTProperty = new OT()”.

Advertisements
This entry was posted in LightSwitch and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s