问题描述
我有一个列和多行的数据网格。单击单元格时,单元格可编辑。我有一个断言,如果我将单元格值编辑为零并单击下一个单元格,则应在该位置删除单元格(0.00)。但运动我点击下一个单元格 cellEditEnd
方法被调用,在这个方法中,我已经编写了删除单元格的代码。但当它尝试删除单元格但代码 datagrid.rows.RemoveAt(index)
然后异常抛出操作无效,因为它导致可重入调用SetCurrentCellAddressCore函数。谷歌搜索时发现了这种情况下的许多解决方法,例如使用带有deegate的beginivoke方法或设置焦点一些控制或在删除单元格之前对网格进行Disbale。但我没有得到解决方案。从网格中删除行时抛出异常。
下面是堆栈跟踪:
Hi,
I have a datagrid of one column and many rows. Cell become editable when i click on the cell. i have a stutation in which if i edit the cell value to zero and click on the next cell then leaving cell (0.00) should be remove at that location. But movement i click on next cell cellEditEnd
methos gets called and in this method i have written the code to remove the cell. But when it try to remove the cell but code datagrid.rows.RemoveAt(index)
then exception throws "Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function".While googling i found many workaround for this case e.g Using beginivoke method with deegate or set focus some aother controls or Disbale the grid before the remove cell. But i didn't got the solution. Exception throws when removing the rows from the grid.
Below is stack trace:
---> System.InvalidOperationException: Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.
at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
at System.Windows.Forms.DataGridView.OnRemovingRow(Int32 rowIndexDeleted, Point& newCurrentCell, Boolean force)
at System.Windows.Forms.DataGridViewRowCollection.RemoveAtInternal(Int32 index, Boolean force)
at System.Windows.Forms.DataGridViewRowCollection.RemoveAt(Int32 index)
我的代码是simmilar at下面:
MY code is simmilar at below:
private void grdListItems_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (cellAmt == 0)
{
RemoveZeroDollarEntry(e.RowIndex);
}
}
And
private void RemoveZeroDollarEntry(int rowIndex)
{
do something...
grdListItems.Rows.RemoveAt(rowIndex);
}
任何人都能提供正确的解决方案吗?请。
谷歌搜索我去了下面的位置
推荐答案
myDataGridView.MultiSelect=false;
这篇关于操作无效,因为它导致对SetCurrentCellAddressCore函数的可重入调用“。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!