本文介绍了如何规避折返调用setCurrentCellAddressCore?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个是从cell_endedit调用的函数。它移动一个的DataGridViewRow一个DataGridView里面:
私人无效moveRowTo(DataGridView的表,诠释oldIndex,诠释newIndex)
{
如果(newIndex< oldIndex)
{
oldIndex + = 1;
}
,否则如果(newIndex == oldIndex)
{
的回报;
}
table.Rows.Insert(newIndex,1);
的DataGridViewRow行= 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]。可见=虚假的;
table.Rows.RemoveAt(oldIndex);
table.Rows .Selected [oldIndex] = FALSE;
table.Rows .Selected [newIndex] = TRUE;
}
在排table.Rows.Insert(newIndex,1)我得到以下错误:
It happens when I click another cell in process of editing current cell.How do i evade such error and have my row inserted correctly?
解决方案
This error is caused by
As the accepted answer in this post.
The fix (I have verified): use BeginInvoke
to call moveRowTo
.
private void dataGridView2_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
this.BeginInvoke(new MethodInvoker(() =>
{
moveRowTo(dataGridView2, 0, 1);
}));
}
Why it works (In My Opinion): BeginInvoke
is an asynchronous call, so dataGridView2_CellEndEdit
returns immediately, and the moveRowTo
method is executed after that, at that time dataGridView2
is no longer using the currently active cell.
这篇关于如何规避折返调用setCurrentCellAddressCore?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!