我在第一列中有 aDataGridView
与a和 a绑定(我没有设置 valeumember,因为我想在访问值时获取 myclass )。第二列也是。它将基于第一个selectedValue 绑定到一些。DataGridViewComboBoxColumn
List<MyClass>
DisplayMember="name"
DataGridViewComboBoxColumn
List<String>
DataGridViewComboBoxColumn
所有这些工作都很好,当我更改第一个DataGridViewComboBoxColumn.DataSource
. 当我向数据源添加一个新的 Myclass 时,它可以工作,但是如果我选择该类,我会收到一个错误:
System.ArgumentException:DataGridViewComboBoxCell 值无效
代码:
//Set columns to Datagridview
DataGridViewImageColumn btnEdit = new DataGridViewImageColumn();
Image gear = (System.Drawing.Image)Properties.Resources.gear;
btnEdit.Image = gear;
datagridview.Columns.Add(btnEdit);
//Table
DataGridViewComboBoxColumn cbTable = new DataGridViewComboBoxColumn();
cbTable.HeaderText = "Table";
cbTable.Name = "Table";
cbTable.DisplayMember = "NameToShow";
//tableDataSource = cbTable.DataSource;
//cbTable.DataSource = moduleClone.SqlQuery.Tables;
datagridview.Columns.Add(cbTable);
//...
//...
//...
//Load data
((DataGridViewComboBoxColumn)datagridview.Columns[1]).DataSource = (List<Table>)moduleClone.SqlQuery.Tables;
//Work just fine
//...
//...
//...
//Now if i reload de data
datagridview.Rows.Clear();
((DataGridViewComboBoxColumn)datagridview.Columns[1]).DataSource = (List<Table>)moduleClone.SqlQuery.Tables;
//This give me one message box with the exception several times when drawing the gridview.