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 GridTextColumn with numeric values based on the Regional settings of the system?

Platform: WPF |
Control: SfDataGrid |
.NET Framework: 4.5

You can format the GridTextColumn by using GridTextColumn.DisplayBinding. You can either use the Binding.StringFormat property (only for WPF) or Binding.Converter for formatting the GridTextColumn. GridTextColumn formats the data based on the InvariantCulture. To format based on the system’s regional settings, CurrentCulture, use the Converter as given in the following code. The Converter is defined to convert the decimal values based on CurrentCulture.

 

public class FormatConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        Var columnValue = System.Convert.ToDecimal(value);
        return columnValue.ToString("N", CultureInfo.CurrentCulture.NumberFormat);
    }
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return new NotImplementedException();
    }
}

 

Converter is set to the GridTextColumn.DisplayBinding to format the column based on CurrentCulture instead of InvariantCulture.

 

<Window.Resources>
     <local:FormatConverter x:Key="formatConverter"/>
</Window.Resources>
<Syncfusion:GridTextColumn MappingName="EmployeeSalary" 
                           DisplayBinding="{Binding Path=EmployeeSalary,
                           Converter={StaticResource formatConverter},Mode=TwoWay}"/>
</Syncfusion:SfDataGrid.Columns>

 

You can use the GridNumericColumn to format the decimal values based on the CurrentCulture, by default.

 

 

Sample Links:

 

WPF

WinRT

UWP

 

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

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