There is an issue: I sometimes add/remove columns of my datatable. Now when I bind Grid directly to DataTable, it changes FieldLayout properly and defines new columns. But if I bind to any list of DataRows from this table, FieldLayout becomes corrupted and I get following binding error:
GetCellValue failed, exception type: System.ArgumentException, exception msg: Column 'C3' does not belong to table DataTable1., item index: 8, DataItem: DynamicGridBug.DataSet1+DataTable1Row
I've attached the sample project. If you click 'source 1', 'source 2', 'source 1', you will see that C3 column is empty are there are lots of binding errors.
The only way to overcome this is to create new DataTable each time, and then it seems to work.
Any ideas?
private void Button_Click(object sender, RoutedEventArgs e)
{
grid.DataSource = null;
DS.DataTable1.Rows.Clear();
DS.DataTable1.Columns.RemoveAt(3);
DS.DataTable1.Columns.Add("C3");
for (int i = 0; i < 10; i++)
DS.DataTable1.Rows.Add(new object[] { i, "1", "2", "3" });
grid.FieldLayouts.Clear();
grid.DataSource = new List<DataRow>((from r in DS.DataTable1 select r).ToList()); // bad
// grid.DataSource = DS.DataTable1; // good
}
private void Button_Click_1(object sender, RoutedEventArgs e)
DS.DataTable1.Columns.Add("C4");
DS.DataTable1.Rows.Add(new object[] { i, "1", "2", "4" });
grid.DataSource = DS.DataTable1; // good
// grid.DataSource = new BindingList<DataSet1.DataTable1Row>((from r in DS.DataTable1 select r).ToList()); // bad
Hello Eugene,
Thank you for your post.
I have been looking into your sample application and it seems that your issue is not related with Infragistics controls. What I can suggest is to take a look at the Microsoft forum for similar issues or ask Microsoft experts about this behavior. You can take a look at the following link, it can be of help to you:
https://social.msdn.microsoft.com/Forums/en-US/927a348e-80ef-475e-90c7-b8be2a27e707/systemargumentexception-column-columnname-does-not-belong-to-table?forum=winformsdatacontrols
http://stackoverflow.com/questions/20962923/column-abc-does-not-belong-to-table
Please let me know if you need any further assistance on the matter.
Hello,
I am just checking if there is anything else I can do for you.
Well, I didn't find any way for grids to work properly than to linking the grid directly to DataTable. Any other way is prone to issues.