I have to dynamically generate a table I use for datasource. As I add or subtract columns everything seems to be working. The problem comes when I remove the last displayed column, the view still shows the column with all the rows. Although if I click a row I get a RowNotInTableException. Am I doing something wrong?
The pertinent code is :
dataGridView1.GridElement.BeginUpdate();
dataGridView1.DataSource = CalculateTable(...);
dataGridView1.GridElement.EndUpdate();
The CalculateTable method returns null if there is nothing to do. Should I return an empty table instead, or is it some update thing I am not doing?
5 Answers, 1 is accepted
Thank you for contacting us.
We would like to investigate this scenarion in additional detail. Please send us a simple project reproducing the behavior you describe. It will help us address any potential issue faster.
If you have any additional questions, please write us again.
Best wishes,
Julian Benkov
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
It is probably easier to just reproduce it yourself by creating a new windows app, add two buttons and a radgridview.
on button 1 (columns) click event:
gridList.GridElement.BeginUpdate();
gridList.DataSource = CalculateTable(
false);
gridList.GridElement.EndUpdate();
on button 2 (null) click event:
gridList.GridElement.BeginUpdate();
gridList.DataSource = CalculateTable(
true);
gridList.GridElement.EndUpdate();
private DataTable CalculateTable(bool returnNullTable)
{
if (returnNullTable == true)
return null;
DataTable dt = new DataTable("TestTable");
dt.Columns.Add(new DataColumn("TestColumn", Type.GetType("System.String")));
string[] item = new string[1];
item[0] = "test 0";
dt.Rows.Add(item);
item[0] = "test 1";
dt.Rows.Add(item);
item[0] = "test 2";
dt.Rows.Add(item);
return dt;
}
if you click columns, then null, the rows are still present, and if you select a row you go kaboom. Am I doing something wrong?
Sorry for the inconvenience.
We have found an issue with the DataSource when it is reset to null in RadGridView in our current release. For the time being, you can use this workaround:
on button 2 (null) click event: |
gridList.GridElement.BeginUpdate(); |
gridList.DataSource = CalculateTable(true); |
((GridTableElement)gridList.GridElement).TableBodyElement.Children.Clear(); gridList.GridElement.EndUpdate(); |
The issue will be addressed for our next release. Your Telerik points have been updated.
We'll be glad to help you with any additional questions.
Best wishes,
Julian Benkovthe Telerik team
Instantly find answers to your questions at the new Telerik Support Center
private
DataTable CalculateTable(bool returnNullTable)
{
DataTable dt = new DataTable("TestTable");
if (returnNullTable == true)
return dt;
...
}
Thank you for sharing your workaround with the community. Your Telerik points have been updated.
Sincerely yours,
Kiril
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center