Articles in this section
Category / Section

How to format the GridTextColumn with numeric values based on the Regional settings of the system in WPF DataGrid?

3 mins read

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

 

Conclusion

I hope you enjoyed learning about how to format the GridTextColumn with numeric values based on the Regional settings of the system.

You can refer to our WPF Grid feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF Grid documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied