We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to format the GridNumericColumn in the SfDataGrid?

Platform: WPF |
Control: SfDataGrid |
.NET Framework: 4.5 |
Product Version: 12.4.0.24

In the SfDataGrid, you can display the double type values by using the GridNumericColumn. By default, it loads the TextBlock in the display mode and the DoubleTextBox in the edit mode. You can format the value of the GridNumericColumn by using its inbuilt properties. The following screenshot shows the Annual Income of the GridNumericColumn loaded with its default value without formatting.

Figure 1: Default view of the GridNumericColumn

 

The following XAML code example shows how to format the GridNumericColumn with the built-in properties.

XAML

  • NumerDecimalDigits: NumerDecimalDigits is a dependency property and its type is an Integer. It specifies the number of decimal places to use the numeric value in editor.
  • NumberDecimalSeparator: NumberDecimalSeparator is a dependency property and its default type is string. It separates the integer from the fractional digits.
  • NumberGroupSeparator: NumberGroupSeparator is a dependency property and its default type is string. It separates groups of digits to the left of the decimal in numeric values.
  • NumberGroupSizes: NumberGroupSizes is a dependency property that specifies the Int32Collection or a single digit number. It is used to specify the number of digits in each group to the left of the decimal in numeric values.

The above specified format is applied to the GridNumericColumn as shown in the following screenshot.

Figure 2: After formatting the values in GridNumericColumn

 

In the GridNumericColumn, it is not possible to format the scientific notation since the StringFormat property is applicable only for the GridTextColumn. You can achieve this behavior with the help of the converter in the DisplayBinding property and format the display of the GridNumericColumn.

The following XAML code example shows how to display the scientific notation in the GridNumericColumn by using the converter in the DisplayBinding.

XAML

The above converter is invoked for each cell in the GridNumericColumn and the display format can be customized based on the specified format provided in the converter as shown in the following code example.

C#

The above scientific notation format is applied into the GridNumericColumn as shown in the following screenshot.

Figure 3: Scientific Notation in GridNumericColumn

 

You can refer to the sample from the following location.

WPF: GridNumericColumn_WPF.zip

WRT: GridNumericColumn_WRT.zip

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Ed Seng
Jul 27, 2017

A lot of effort to just get the basic options for numeric formatting. 

Reply
Srinivasan Vasu [Syncfusion]
Jul 28, 2017

Hi Ed Seng,

You can get basic options for Numeric Column formatting from below link:

https://help.syncfusion.com/wpf/sfdatagrid/column-types#gridnumericcolumn

https://help.syncfusion.com/wpf/sfdatagrid/column-types#data-formatting-1

Regardss,

Srinivasan


Ed Seng
Jul 27, 2017

A lot of effort to just get the basic options for numeric formatting. 

Reply
Mike Christie
Oct 31, 2020

There are powerful options but why can't we also just have a simpler option in WPF to use normal formatting like {0:C} or {0:N2} or even beter the FormatString option that UWP has? It's crazy (and un-necessary) to have to add 3, 4 or 5 different parameters just to get a double or decimal formatted with commas and decimal places! Please fix this!!

Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile