Articles in this section
Category / Section

How to pass the whole data object (for the grid line) to a converter?

1 min read

By default, SfDataGrid passes the value associated with the property in a DisplayBinding.Converter. In order to, pass the whole data object to the converter, you need to specify the BindingPath of the DisplayBinding as “.” (dot).

Refer the below code which illustrates setting BindingPath as “.” to pass the entire associated underlying data as a parameter to the Converter.

datagrid.AutoGeneratingColumn += Datagrid_AutoGeneratingColumn;  
 
private void Datagrid_AutoGeneratingColumn(object sender, AutoGeneratingColumnArgs e)
{
   if(e.Column.MappingName=="CustomerName")
    {
        e.Column.LoadUIView = true;
        e.Column.DisplayBinding = new Binding(".", BindingMode.Default, new ConvertCustomerName());
    }
}

 

The following code gives the implementation of the converter to get the data object.

public class ConvertCustomerName : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value != null && value is Model)
        {
            return (value as Model).ToString();
        }
        return null;
    }
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

 

On executing the above code, you will get the output as shown below:

C:\Users\suhasini.suresh\Documents\Word\Screenshot_2017-01-12-17-31-44_SampleXamarin_5103.Droid.png

 

Sample Link:

How to pass the whole data object (for the grid line) to a converter

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