Dynamic DataGrid Columns RRS feed

  • Question

  • I guess this question is more about logic than how to do it. I found this and it's pretty much straightforward to create DataGridColumns from code behind.

    However, in my scenario I have two DateTime's property, and I want to generate the Columns from every day between that two DateTimes.

    public class Data
          public DateTime StartDate {get; set;}
          public DateTime EndDate {get; set;}

    Example: if StartDate is 2012/05/21 and EndDate is 2012/05/23, then I have to generate 3 columns, each one's header beeing the date, and each one's value cells beeing some other value (that I don't know how to bind to the ItemsSource).

    Other problem is how the properties of the underlying bound object will be declared... I mean, I would have something like that I think:

    public class Model
          public string Description {get; set;} // this column is not dynamic
          public Dictionary<DateTime,decimal> Values {get; set;} // dynamic columns (DateTime would be Header and decimal would be the value of the cell)
    Wednesday, May 23, 2012 8:57 AM

All replies