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.
Unfortunately, activation email could not send to your email. Please try again.

Dynamic columns creation through data binding

Thread ID:

Created:

Updated:

Platform:

Replies:

118813 Apr 10,2015 04:59 PM Jun 16,2015 05:31 AM WinRT 9
loading
Tags: SfDataGrid
Vasanth
Asked On April 10, 2015 04:59 PM

Hi,
I am wondering if there a way to dynamically create columns using data binding. Lets says I have a class like below:

Student
{
int ID, 
string Name
List<Subject> SubjectList
)

Columns: ID, Name will be statically bound and I like to create one column per Subject in SubjectList collection with subject name as header text and subject.Score will be its value.  

Jai Ganesh S [Syncfusion]
Replied On April 13, 2015 09:58 AM

Hi Vasanth,

Thank you for using Syncfusion products.

We have analyzed your query. You can achieve your requirement for dynamically adding the columns and set the SubjectName as HeaderText and scores as values by using Indexer binding. We have prepared a sample based on this and please find the sample under the following location,

Sample: http://www.syncfusion.com/downloads/support/directtrac/137656/SfGridComplexPropertySample-1400735603.zip

Please let us know if you need further assistance.

Thank you,

Jai Ganesh S


Vasanth
Replied On April 13, 2015 10:09 AM

Thanks for prompt response Jai Ganesh! I looked at the sample and  dynamic columns are being achieved in code behind. I am wondering if there a way I can do that in xaml? Also the Subjects collection is a variable so I would want the XAML binding to create those columns dynamically as well.

Jai Ganesh S [Syncfusion]
Replied On April 14, 2015 05:33 AM

Hi Vasanth,

 

Thank you for the update.

 

We have analyzed your query. You can also create the columns by using  indexer binding in Xaml like code behind. We have modified the sample based on this and please find the sample under the following location,

 

Sample:

http://www.syncfusion.com/downloads/support/directtrac/137224/SfGridComplexPropertySample-363928122.zip

 

Please let us know if you need further assistance.

 

Thank you,

Jai Ganesh S


Vasanth
Replied On April 14, 2015 09:45 AM

Hi Jai Ganesh,
Thanks for the sample! Binding in XAML is still being acheived in static way. You are currently adding four hard coded columns with subject indexer from 0-3. But the number of subjects can vary so I am wondering if I can dynamically create columns in XAML based on variable number of subjects.
 
Vasanth

Jai Ganesh S [Syncfusion]
Replied On April 15, 2015 06:43 AM

Hi Vasanth,


We areunclearabout how SfDataGrid generatescolumns for the indexer properties. If you are expecting something like similar to SfDataGrid.AutoGenerateColmns property, thenit is not possible to auto generate columns for complex/indexer properties. If you want to add columns dynamically,then you have to use code behind to add columns based onyour requirement.


We have support to auto generate columns of direct properties of data by setting SfDataGrid.AutoGenerateColumns. But, you have to define column in XAML or you have to add columns from code behindfor complex and indexer property.


Please let us know if you need further assistance.


Thank you,

Jai Ganesh S



Vasanth
Replied On April 15, 2015 09:42 AM

Hi Jai Ganesh,

Yeah I was hoping it will be possible to dynamically create columns for indexer properties in XAML. I really appreciate your help  & effort. thanks!

Saranya CJ [Syncfusion]
Replied On April 16, 2015 04:51 AM

Hi Vasanth,

Thank you for your update. Please let us know if you require further assistance on this.

Regards,
Saranya

Sreeram Akella
Replied On June 15, 2015 12:11 PM

Hi, 

I have a very similar requirement in one of my projects and so I used your sample. However, I found that the DataGrid crashes while trying to sort the generated columns. In the sample, when I tried to sort "Physics" column, the grid crashes with an exception message, 'SubjectList[0]' is not a member of type 'SfGridComplexPropertySample.Student'. 

Is there a different way to achieve dynamic columns? I remember solving a similar problem in WPF using ICustomTypeDescriptor implementation (Much cleaner and testable approach)Does SfDataGrid support this interface or anything similar?

Thanks,
Ram.

Jai Ganesh S [Syncfusion]
Replied On June 16, 2015 05:31 AM

Hi Vasanth,

We are sorry about the inconvenience caused.

We analyzed your query. You can achieve your requirement by setting “UseBindingValue” property as true in the column. When we set UseBindingValue property in GridColumn to true then Sorting, Grouping and Filtering make use of binding defined in GridColumn instead of reflection to manipulate the data.

Code Snippet [XAML]:

<syncfusion:GridTextColumn MappingName="SubjectList[0].Score" HeaderText="Physics" UseBindingValue="True"/>


We have also modified the sample based on this and please find the sample under the following location:

Sample: http://www.syncfusion.com/downloads/support/directtrac/126438/ze/SfGridComplexPropertySample2100089253

Please find the following Kb link to shows the UseBindingValue in Complex properties,

Kb Link:

http://help.syncfusion.com/ug/wpf/index.html#!Documents/complexpropertybinding.htm

Please let us know if you need further assistance.

Thank you,

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.

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.

;