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

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

Thread ID:

Created:

Updated:

Platform:

Replies:

121811 Jan 27,2016 08:04 PM UTC Feb 2,2016 03:42 AM UTC WPF 5
loading
Tags: GridDataControl
Steve McWilliams
Asked On January 27, 2016 08:04 PM UTC

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.

Sowndaiyan Paulpandi [Syncfusion]
Replied On 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



Regards,

Sowndaiyan


Steve McWilliams
Replied On 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";

runDataGrid.VisibleColumns.Add(col1);

var col2 = new GridDataVisibleColumn();

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

col2.HeaderText = "Country";

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

runDataGrid.VisibleColumns.Add(col2);


Sowndaiyan Paulpandi [Syncfusion]
Replied On 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,

C#


           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";


            dataGrid.VisibleColumns.Add(col2);




Regards,

Sowndaiyan




Steve McWilliams
Replied On February 1, 2016 02:40 PM UTC

Thanks a lot !
That works great now

Sowndaiyan Paulpandi [Syncfusion]
Replied On February 2, 2016 03:42 AM UTC

Hi Steve,

Thanks for the update.

Please let us know if you need further assistance.
Regards,
Sowndaiyan

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

;