【发布时间】:2014-10-23 07:09:22
【问题描述】:
我有一个从 cell_endit 调用的函数。它在 dataGridView 中移动 dataGridViewRow:
private void moveRowTo(DataGridView table, int oldIndex, int newIndex)
{
if (newIndex < oldIndex)
{
oldIndex += 1;
}
else if (newIndex == oldIndex)
{
return;
}
table.Rows.Insert(newIndex, 1);
DataGridViewRow row = table.Rows[newIndex];
DataGridViewCell cell0 = table.Rows[oldIndex].Cells[0];
DataGridViewCell cell1 = table.Rows[oldIndex].Cells[1];
row.Cells[0].Value = cell0.Value;
row.Cells[1].Value = cell1.Value;
table.Rows[oldIndex].Visible = false;
table.Rows.RemoveAt(oldIndex);
table.Rows[oldIndex].Selected = false;
table.Rows[newIndex].Selected = true;
}
在行 table.Rows.Insert(newIndex, 1) 我得到以下错误:
“System.InvalidOperationException”类型的未处理异常 System.Windows.Forms.dll
附加数据:操作无效,因为它会导致对 SetCurrentCellAddressCore 函数的可重入调用。
当我在编辑当前单元格的过程中单击另一个单元格时会发生这种情况。 我如何避免这样的错误并正确插入我的行?
【问题讨论】:
-
我在使用 ReadOnly = True 和 FullRowSelect 模式(.NET 4.6.2 Windows 窗体,VS2019)的 DataGridView 中遇到相同的错误
标签: c# datagridview invalidoperationexception