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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Dynamically adding and binding columns

Thread ID:





103058 Mar 27,2012 03:36 PM UTC Apr 20,2016 01:28 AM UTC WPF 12
Tags: GridDataControl
Ophir Aharoni
Asked On March 27, 2012 03:36 PM UTC


I was wondering if it was possible, and if so how, to add "dynamically" columns to a wpf data grid in syncfusion.

Say I have a hypothetical class that has a few properties:

public class Player
public string Name { get; set; }
public string Position { get; set; }

public List PointsPerVenue { get; set; }

where PointsPerVenue would be a list an unknown size that lists the points a certain player scores in a certain venue.

now in my ViewModel I would have an ObservableCollection that I would probably bind my datagrid's itemsource to.

I would also have a List property that would list the venues the group of player showed in my datagrid played in.


public class ViewModel1
public ObservableCollection PlayerGroup {get;set;}
public List Venues { get; set; }

Can I somehow dynamically add the columns where the venues list would be the column header's and the cells would be bound to the appropriate member of the Player's PointsPerVenue list?


Sankara Narayanan N [Syncfusion]
Replied On April 9, 2012 07:17 PM UTC

Hi Oaha,

Thanks for using Syncfusion products.

we have prepared a sample as per your query and please find the sample from the attachment.

In the sample, we have achieved your requirement by binding the Venus as like complex property binding and it is not possible to bind a collection which a collection with it. if you want to achieve your requirement, you can have separate collection and that can be bound to a column or else you can use nested grid.

Please let us know if you have queries.



Keller Grimmitt
Replied On January 31, 2013 06:12 PM UTC

Is there any way to do this in the xaml code?  I'd like to bind to a list and have syncfusion grid create a column for each object in the list.  

Rajasekar G [Syncfusion]
Replied On February 5, 2013 04:33 AM UTC

Hi Keller, 

Thank you for your update.

We have analyzed your query and we have achieve your requirement by using the following code snippet. 

Code Snippet[Xaml]:



                        ItemsSource="{Binding GDCSource}" 



                        local:GDCAttachedProperty.DynamicColumns="{Binding VisibleColumns}">         



We have prepared a sample based on this and it can be download from the following location. 

Sample Location: GridDataControl_VisibleColumnsBinding.zip 

Please let us know if you have any questions. 


Raja sekar.G

Rajiv Verma
Replied On September 11, 2013 10:12 AM UTC

The XAML binding solution zip file link is broken. Please provide the correct link.

Darren Baines
Replied On September 17, 2013 02:30 PM UTC

I also need a copy of this file. Please fix the broken link.

Gobinath A [Syncfusion]
Replied On September 19, 2013 08:34 AM UTC

Hi Darren,

We apologies for  the delay caused.

The provided sample was unable to download at you end might be because of our server issue. We have reloaded the sample again and could you please check now.

Sample: GridDataControl_VisibleColumnsBinding.zip

Please let us know if you have any queries.


Gobinath A

Replied On April 10, 2016 06:44 PM UTC

Can you reupload the sample? I would need this.


Jayapradha S [Syncfusion]
Replied On April 12, 2016 09:34 AM UTC

Hi koanbock,

Please find the sample from the following location,
Sample Link: http://www.syncfusion.com/downloads/support/forum/103058/ze/GridDataControl_VisibleColumnsBinding83567388


Replied On April 17, 2016 08:17 PM UTC

Thanks for hte reupload!

I looked into it and have a short question about the binding.

Can I bind a Column to an Arrayitem?

Something like 

 for (var i = 1; i <= length; i++)
   list.Add(new GridDataVisibleColumn() { HeaderText = i.ToString(), MappingName = $"ColumnArray[{i}].Text" });


Srinivasan Vasu [Syncfusion]
Replied On April 18, 2016 12:06 PM UTC

Hi koanbock,

We have prepared a sample as per your requirement. In this sample, we have created dynamic VisibleColumns using Indexer Property binding.
Please refer the below code example

private List<GridDataVisibleColumn> Getvisiblecolumn()
            List<GridDataVisibleColumn> list = new List<GridDataVisibleColumn>();       

            for (int i = 0; i < 6; i++)
                var bind  = new System.Windows.Data.Binding()
                    Path =new System.Windows.PropertyPath($"ColumnArray[{i}].Text")

                list.Add(new GridDataVisibleColumn()   // DynamicColumns
                    MappingName = $"ColumnArray[{i}].Text",
                    Binding = bind,
                    //Must set this property to let the GridDataControl know the type of property, you are binding when using arrarys
                    VisibleColumnType = typeof(string)
            return list;

        private ObservableCollection<Data> Getsource()
          ObservableCollection<Data> items = new ObservableCollection<Data>();

            if (items != null)
                for (int i = 0; i < 6; i++)
                    Data data = new Data();
                    for (int j = 0; j < 6; j++)
                        data.ColumnArray[j] = new Model();
                        data.ColumnArray[j].Text = "customer" + i;
            return items;

Please find the sample from the below location:

Please let us know if you have queries.

Replied On April 18, 2016 05:14 PM UTC


thanks for the sample working like a charm creating the columns but when I change the Row 1 Column 1 Text and move to the next row it gets the same value. Seems like the control doesnt update properly.


Srinivasan Vasu [Syncfusion]
Replied On April 20, 2016 01:28 AM UTC

Hi koanbock,

In GridDataControl, while binding columns dynamically the same value updated in all rows of same column when editing the data. This is actual behavior of  GridDataControl. So, we have recommended you to use only SfDataGrid in your application and currently we have implemented many features in SfDataGrid. SfDataGrid has been designed based on the WPF template-based architecture which provides support to customize the Grid easily. Comparatively, the performance of SfDataGrid control is better than the GridDataControl.

UG Link: http://help.syncfusion.com/wpf/sfdatagrid/overview

Please let us know if you have any concerns.



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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

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