"0" Custom Format Specifier in LightSwitch 2012

Here we will see how to use the "0" Custom Format Specifier in LightSwitch Visual Studio 2012.

"0" Custom Format Specifier

The "0" Custom Format Specifier serves as a Zero-Placeholder Symbol. Let us suppose that a value being formatted has some digits in the position where the zero (0) appear in the string, that digit is copied as it is to the output string. Otherwise a zero appears in the output string.

The position of the left side zero before the decimal point and the right side zero after the decimal point determines the range of the digit present in a string.

The following is the procedure for creating a sample use of the Zero-Placeholder on a Screen.

Step 1

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

Solution Explorer

Right-click on "Data Sources" and choose "Add Table".

Add Table

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

Student Table

In the preceding table I have added a record named "Fees" and I have set its datatype to "double".

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

Screen Designer.jpg

Step 3

Press F5 to run the application. Provide the information and we will get the following output.

Output of Editable Screen

Step 4

Stop debugging the application. Now go to the Format Pattern of Property window in the table designer. Enter "0000" as the specifier in the format pattern of the Property window. 

ZeroPlaceHolder Format Pattern

Once again press F5 to run the application. We will get the following output as shown below.

Output showing Zero PlaceHolder

Step 5

Stop debugging the application. Once again go to the Format Pattern of Property window in the table designer. This time enter "000" as the specifier in the format pattern of the Property window.

Format Pattern for three digit place holder

Once again press F5 to run the application. This time we will get the following output as shown below.

output showing three zero placeholder

Step 6

Stop debugging the application. Once again go to the Format Pattern of Property window in the table designer. This time enter "00" as the specifier in the format pattern of the Property window. 

Two ZeroPlaceHolder in Format pattern.jpg

Once again press F5 to run the application. This time we will get the following output.

Output for Editable Grid Screen

Note: The "00" specifier causes the string value to be rounded to the nearest digit preceding the decimal. For example: formatting 37.5 with "00" would result in the value 38.

Up Next
    Ebook Download
    View all
    Learn
    View all