Columns not generated with ItemsSource

2 posts, 0 answers
  1. Gen
    Gen avatar
    15 posts
    Member since:
    Nov 2010

    Posted 05 Jan 2012 Link to this post

    Hello,

    I have the following bit of code, to dynamically create a GridView with a random number of columns.
    The DataTable/DataColumn are from this blog: http://blogs.telerik.com/vladimirenchev/posts/09-04-23/lightweight-datatable-for-your-silverlight-applications.aspx
    using Telerik.Data;
    ...
      
    DataTable gridSource = new DataTable();
      
    gridSource.Columns.Add(new DataColumn() { ColumnName = "ID", DataType = typeof(Int32) });
    gridSource.Columns.Add(new DataColumn() { ColumnName = "USERID", DataType = typeof(Int32) });
    gridSource.Columns.Add(new DataColumn() { ColumnName = "FULLNAME", DataType = typeof(String) });
    gridSource.Columns.Add(new DataColumn() { ColumnName = "DATESTART", DataType = typeof(DateTime) });
    gridSource.Columns.Add(new DataColumn() { ColumnName = "DATEEND", DataType = typeof(DateTime) });
      
    int iColumnId = 0;
    foreach (int week in MyDynamicNbOfWeeks)
    {
        iColumnId++;
        gridSource.Columns.Add(new DataColumn() { ColumnName = "date" + iColumnId.ToString(), DataType = typeof(Decimal) });
    }
      
    //bind the datatable to the grid.
    radTimeLineGridView.ItemsSource = gridSource;
      
    radTimeLineGridView.Columns[0].IsVisible = false;//problem here

    This used to work fine with version 2011.2.712.1040. But with newer version (ex. 2011.3.1116.1040), it crashes on the last line (radTimeLineGridView.Columns[0].IsVisible = false;) because the Columns list is empty.

    In the older version, the RadGridView columns are generated as soon as the ItemsSource is set, witch is not the case in the newer version.
    What has changed to make this stop working? Is there any way around?

    Thank you,
    Gen
  2. Gen
    Gen avatar
    15 posts
    Member since:
    Nov 2010

    Posted 12 Jan 2012 Link to this post

    In case anyone else is experiencing this, the easy way around is adding this bit of cade right after setting the ItemsSource:
    for (int i = 0; i < gridSource.Columns.Count; i++)
    {
        radTimeLineGridView.Columns.Add(new GridViewDataColumn());
    }

    Not exactly pretty, but it works.

    To Telerik,
    Any idea why this is required now?
Back to Top