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

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

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:

01/01/201602/01/201603/01/201604/01/201605/01/201606/01/201607/01/201608/01/2016
Apple123456789987654321123456
Orange789987654321123456789987

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.

5 Replies

JG Jai Ganesh S Syncfusion Team 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

Regards,
Jai Ganesh S


PA Pavel September 21, 2021 11:27 AM UTC

Hi, how can i get this example?



BT Balamurugan Thirumalaikumar Syncfusion Team September 22, 2021 10:46 AM UTC

Hi Pavel, 

Thank you for interesting in Syncfusion products. 

You can download the sample from following link. 


Balamurugan Thirumalaikumar  
  




RM Ramesh Mahadevan (RBEI/EDC1) April 19, 2023 06:17 AM UTC

Hello,


How can I download this sample. I get Access denied message


Thanks



DM Dhanasekar Mohanraj Syncfusion Team April 20, 2023 01:54 PM UTC

Ramesh Mahadevan,

We regret the inconvenience caused,

Here you can get the requested sample.


Attachment: SfGridDemo1612589586_25678f2b.zip

Loader.
Live Chat Icon For mobile
Up arrow icon