"#" Custom Format Specifier in LIghtSwich 2012

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

The "#" custom format specifier is also known as a digit-placeholder symbol. Suppose the value to be formatted has a digit where the "#" symbol appears in the format string, that digit is copied to the output string. Otherwise, nothing is stored in that position in the output string as shown below in the example.

Note: the "#" custom format specifier does not represent a zero, in other words it is not a significant digit, even if zero is the only digit that the string consists of. It will display zero in output only if it is a significant digit.

The "##" format specifier results in the value being rounded to the nearest digit preceding the decimal. For example, formatting 44.5 with "##" would result in the value 45.


Use the following procedure to create a sample use of Standard Numeric Format Strings 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

Here in the table I have added a record named "Fees" and I have taken its datatype as "Double" as shown.

Step 2

Select the "Fees" record from the table and go to the Property window and provide "#.##" under Format Pattern TextBox. 

Select Fees from Table

Format Pattern Property window

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 the 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 Grid Screen using  Digit placeholder

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

Output on Save

Step 4

Now stop debugging the application. Once again go to the Format Pattern of Property window in the table designer. This time enter "###" in the format pattern of the Property window.

Format pattern Properties

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

Inserting Data on Screen

Click on the "Save" Button as shown below.

After Saving data


Similar Articles