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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Binding and Formatting Datagrid Values

Thread ID:

Created:

Updated:

Platform:

Replies:

125748 Sep 8,2016 03:02 PM UTC Sep 15,2016 04:51 AM UTC UWP 5
loading
Tags: SfDataGrid
Francis
Asked On September 8, 2016 03:02 PM UTC

Hi,

I have an object with several properties which are currently in a list and displayed in a datagrid using Mapping Name on manually defined columns.
For some of these properties such as 'Price' and 'Price Increase' I would like to format the value to have it in percentage or currency format.
Typically for other controls I would bind to the property and use a converter, however I seem to unable to do this as if I try using ValueBinding instead of MappingName and add a converter, the app crashes before the page loads due to using a converter.
Is there a particular method for formatting values in a datagrid?

Regards

Francis  

Jai Ganesh S [Syncfusion]
Replied On September 9, 2016 02:14 PM UTC

Hi Francis, 
 
We have analyzed your query . You can set the format for GridNumericColumn by using the FormatString property like below, 
 
<!--  GridNumericColumn with FomatString  --> 
                <syncfusion:GridNumericColumn Width="160" 
                                              FormatString="C" 
                                              HeaderText="Annual Income" 
                                              MappingName="Income" /> 
 
In the above code, we have displayed the value in Currency format. 
 
Kb Link:  
 
Regards, 
Jai Ganesh S 


Francis
Replied On September 12, 2016 10:22 AM UTC

Hi,

Thanks for your reply.

I noticed there is no culture property available to format the value to a different currency.
Is there a way to standard way to set this or do I have to explicitly set the format string like the last example in the knowledge base article?

Regards

Francis

Jayaleshwari N [Syncfusion]
Replied On September 13, 2016 05:47 AM UTC

Hi Francis, 
 
We have analyzed your query “Culture property to format the value to different currency”. In SfDataGrid and GrdiNumericColumn, we do not have direct property to achieve your requirement.   However, you can achieve your requirement by using CurrentCulture. 

Below code snippet applies Culture format to all the numeric columns in the grid. 

public MainPage() 
{ 
    this.InitializeComponent(); 
    CultureInfo.CurrentCulture = new System.Globalization.CultureInfo("de-DE"); 
} 

You can allow the culture format to specific column by using DisplayBinding converter like in below code snippet. 

Code C#: Converter – format the value to de-DE culture with currency format. 

public class FormatConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, string language) 
    { 
        var columnValue = System.Convert.ToDecimal(value); 
        return columnValue.ToString("C", new System.Globalization.CultureInfo("de-DE").NumberFormat); 
    } 
 
    public object ConvertBack(object value, Type targetType, object parameter, string language) 
    { 
        throw new NotImplementedException(); 
    }       
} 

Code XAML: GridNumericColumn definition with DisplayBinding converter. 
 
  <syncfusion:GridNumericColumn Width="160"  
                                                     DisplayBinding="{Binding Income, Converter={StaticResource formatConverter}}" 
                                              HeaderText="Annual Income"  
                                              MappingName="Income" /> 

In the above code we have displayed currency in de-DE culture. 

Regards, 

Jayaleshwari N. 


Francis
Replied On September 14, 2016 09:31 AM UTC

Hi,

Thank you that works perfectly now.

Regards

Francis

Jai Ganesh S [Syncfusion]
Replied On September 15, 2016 04:51 AM UTC

Hi Francis, 

Thank you for the update. 

Please let us know if you need further assistance on this. 

Regards, 
Jai Ganesh S 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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

;