How to evade reentrant call to setCurrentCellAddressCore?

北城余情 提交于 2019-11-28 12:19:41
kennyzx

This error is caused by

Any operation that results in the active cell being changed while the DataGridView is still using it

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);
        }));
}

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.

sandra
if (
    (datagridview.SelectedCells[0].RowIndex != datagridview.CurrentCell.RowIndex) ||
    (datagridview.SelectedCells[0].ColumnIndex!= datagridview.CurrentCell.ColumnIndex)
   ) { return; }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!