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
close icon

How can I bind elements with dynamic, user-defined names in a record to my GridDataControl ?

The records in my grid's ItemsSource have properties with known names, which I bind to my GridDataVisibleColumns with MappingName=X, but they also contain a collection / dictionary of user-defined key-value pairs in a property called UserValues. For example: Country -> England, Size -> Large, Direction -> North, etc.  I know the keys when I am ready to display the grid, but I don't know how to define the xaml or xaml.cs code for the MappingName or Binding, since I can't create properties with the key names ahead of time.

Is there a way to bind an accessor method to the column, like GetUserValue(Country), for example ? Or another way to accomplish this ?
I can display a string combining all the user values (MappingName=UserValues) of course, but I would really like to put each one in a separate column.

5 Replies

SP Sowndaiyan Paulpandi Syncfusion Team January 29, 2016 04:08 AM UTC

Hi Steve,

Thanks for contacting Syncfusion Support.

In GridDataControl you can achieve your requirement by using the Indexer property binding on GridColumn MappingName. We have prepared a sample as per your requirement and you can download the same form the below location,

Sample : http://www.syncfusion.com/downloads/support/forum/121811/ze/Indexer_Binding_Demo-1971808909



SM Steve McWilliams January 29, 2016 08:36 PM UTC

Thank you, SownDaiyan.

This works for me now to display a specified 'RunValue' in the dataGrid when I specify the column in the XAML as your example shows.
But since I want to allow the user to choose which columns they want to display, I need to reconfigure the grid columns in cs code also.

I tried the following code, but then the RunValue column is empty, unlike when I use XAML method. The simple Machine property column works fine.
Do I have to do something else to update the grid after defining a column with indexer bindings ?
My column data is all strings, so I omitted the VisibleColumnType line from your example.


var col1 = new GridDataVisibleColumn();

col1.HeaderText = "Machine";

col1.MappingName = "Machine";


var col2 = new GridDataVisibleColumn();

col2.Binding = new Binding("{Binding Path=RunValues[Country].Value,Mode=TwoWay}");

col2.HeaderText = "Country";

col2.MappingName = "RunValues[Country].Value";


SP Sowndaiyan Paulpandi Syncfusion Team February 1, 2016 09:00 AM UTC

Hi Steve

In GridDataControl, you can achieve the Indexer property binding in code behind like the below code example,


           GridDataVisibleColumn col2 = new GridDataVisibleColumn();

            Binding colbinding = new Binding();

            colbinding.Path = new PropertyPath("ShipDetails[ShipCountry].Value");

            colbinding.Mode = BindingMode.TwoWay;

            col2.Binding = colbinding;

            col2.HeaderText = "ShipCountry1";

            col2.MappingName = "ShipDetails[ShipCountry].Value";




SM Steve McWilliams February 1, 2016 02:40 PM UTC

Thanks a lot !
That works great now

SP Sowndaiyan Paulpandi Syncfusion Team February 2, 2016 03:42 AM UTC

Hi Steve,

Thanks for the update.

Please let us know if you need further assistance.

Live Chat Icon For mobile
Up arrow icon