【发布时间】:2015-07-24 14:57:59
【问题描述】:
我正在动态地将数据网格视图添加到表单中。加载表单后,如果用户想要添加新行,我有一个按钮,用户可以使用该按钮添加新行。在此按钮上单击我正在尝试添加一个 DataGridViewComboBoxCell:
DataGridViewRow dtRow = new DataGridViewRow();
dgv1.Rows.Add(dtRow);
int RowIndex = dgv1.Rows.IndexOf(dtRow);
int TotalRowsvailable = NPDESconfigModel.Count; // rows in database
if (RowIndex >= TotalRowsvailable) // to see if this is the new row
{
List<string> a = (from p in y
select p.Point_Name).ToList();
DataGridViewComboBoxCell cbcell = new DataGridViewComboBoxCell();
cbcell.DataSource = a;
cbcell.DisplayMemeber = "Point_Name";
dgv1.Rows[RowIndex].Cells.Add(cbcell);
}
我在代码的最后一行得到的异常如下。 集合已属于 DataGridView 控件。这个操作 不再有效。
不知道是什么意思。
出现异常后,表单会加载新行和空单元格。
【问题讨论】:
标签: c# winforms datagridview datagridviewcomboboxcell