This is a migrated thread and some comments may be shown as answers.

Columns not generated with ItemsSource

1 Answer 35 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gen
Top achievements
Rank 1
Gen asked on 05 Jan 2012, 11:19 PM
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

1 Answer, 1 is accepted

Sort by
0
Gen
Top achievements
Rank 1
answered on 12 Jan 2012, 03:24 PM
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?
Tags
GridView
Asked by
Gen
Top achievements
Rank 1
Answers by
Gen
Top achievements
Rank 1
Share this question
or