Section Separator in LightSwitch 2012

This article describes how to use a section separator(;) in LightSwitch Visual Studio 2012.

It is used to define sections along with separate format strings for positive, negative, and zero numbers.

The semicolon (;) is a conditional format specifier that we can apply to various format patterns. In order
to produce this behavior, a custom format string consists of up to three sections separated by semicolons. These sections are:

  • One section:

    The Format String that applies to all values.
     
  • Two Sections:

    Here the first section of the Format String applies to positive values or zero and the second section applies to negative values. Suppose that the number to be formatted is negative but it becomes zero after rounding then depending on the format pattern for the second section, that zero will be formatted depending on the first section.
     
  • Three Sections:

    Here the first section of the Format String applies to positive values, the second section applies to negative values and the third applies to zero values. Suppose the second section has nothing between the two semicolons. In that case the first section applies to all the values.
    Suppose the number to be formatted consists of non-zero but it becomes zero after rounding then depending on the format pattern for the first or second section then that zero will be formatted depending on the third section.

The following is the procedure for creating a sample showing how to use Section Separator delimiters on a Screen.

Step 1

Open the LightSwitch Application in Visual Studio 2012 and go to the Solution Explorer.

Solution Explorer

Right-click on the Data Source and choose "Add Table".

Add Table

The table appears in the table designer window. Insert the records in the following table.

Student Table

Step 2

Now once again go to the Solution Explorer, right-click on "Screens" and choose "Add Screen".

Add Screen

The Add New Screen dialog box appears. Select the "Editable Grid Screen" from the Screen Template, inside the screen information, choose "Student" under screen data and provide some name to the Screen and click the "OK" button.

Add New Screen

The Screen Designer appears as shown below.

Application Designer

Step 3

Press F5 to run the application. Provide the information. 

Output of Editable Screen

Step 4

Now stop debugging the application. From the Table Designer select the "Fees" record as shown in the figure below.

Select Fees from Student

Then go to the Format Pattern of the Property window in the table designer and enter 
"#0.0#;(#0.0#)" in the format pattern as shown below.

Format Pattern for positive value

Press F5 to run the application. Provide a positive value in the "Fees" column.

Output of Editable Screen

Click on the "Save" button; we will get the following output:

Output for Positive format specifier

Step 5

Now stop debugging the application and then
go to the Format Pattern of the Property window in the table designer and enter "#0.0#;(#0.0#)" in the format pattern as shown below.

Format Pattern for zero value

Once again press F5 to run the application. 
Provide a zero value in the "Fees" column.

Provide zero value in output screen

Click on the "Save" button; we will get the following output.

output showing zero in fees

Step 6

Now stop debugging the application and go to the Format Pattern of Property window in the table designer and enter "#0.0#;(#0.0#)" in the format pattern as shown below.

Format Pattern for negative value

Once again press F5 to run the application. 
Provide a negative value in the Fees column.

Output of Editable Screen

Click on the "Save" button; we will get the following output.

output for negative fees value

Step 7

You can also enter
the "#0.0#;(#0.0#);-\0-" pattern in the format pattern property window.

Format pattern for another zero pattern

Again press F5 to run the application. Provide a zero value in the "Fees" column.

Provide zero value in output screen

Click on the "Save" button; we will get the following output.

Output for another zero format

Up Next
    Ebook Download
    View all
    Learn
    View all