Articles in this section
Category / Section

How to Format GridTextColumn with numeric values in WinRT Grid?

2 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

 

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