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.
Syncfusion Feedback

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

Thread ID:

Created:

Updated:

Platform:

Replies:

121692 Jan 16,2016 07:13 PM Jan 18,2016 07:49 AM WPF 1
loading
Tags: SfDataGrid
Daniel Neve
Asked On January 16, 2016 07:13 PM

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.

Jai Ganesh S [Syncfusion]
Replied On January 18, 2016 07:49 AM

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

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

;