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

How to dynamically add a new column to an SfDataGrid that gets it's values from a dictionary

Thread ID:





121692 Jan 17,2016 12:13 AM UTC Jan 18,2016 12:49 PM UTC WPF 1
Tags: SfDataGrid
Daniel Neve
Asked On January 17, 2016 12:13 AM UTC

I want to display a table of data. Each row is an instance of my class "Fruit", each column is a date.

Sort of like this:


I can store the data however is needed, but both the number of columns and rows is variable.

My hope is that the simplest solution is that I store the data as a Dictionary<DateTime, int> (or perhaps as Dictionary<string, int>) as a child property of Fruit, and set a MappingName along the lines of "FruitDict[01/01/2016]" when adding a new column to display that particular date.

Jai Ganesh S [Syncfusion]
Replied On January 18, 2016 12:49 PM UTC

Hi Daniel,

Yes. You can achieve your requirement using Dictionary type is one of the underlying collection property and display the value in column as mentioned your update.  We have prepared the sample based on this and you can download the sample from the below location,

Code Example: Add Column from XAML

<Syncfusion:GridTextColumn MappingName="dictionary[03/01/2016]" HeaderText="03/01/2016"    />

Code Behind:

private void Button_Click(object sender, RoutedEventArgs e)


            this.datagrid.Columns.Add(new GridTextColumn() { MappingName = "dictionary[04/01/2016]", HeaderText = "05/01/2016" });

Sample: http://www.syncfusion.com/downloads/support/directtrac/147512/ze/SfGridDemo-1612589586

Jai Ganesh S


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

This page will automatically be redirected to the 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