我正在使用 datagridview
开发表单。
我想要的结果是:
- 当用户点击“只读单元格”时,光标将移动到“可编辑单元格”。
- 当用户点击“可编辑单元格”时,光标将位于此“当前可编辑单元格”上。
我在 Cell_Enter 事件
上进行了此操作(我有一些理由在 Cell_Enter
上进行此编码。我必须使用 Cell_Enter)。
DataGridViewCell cell = myGrid.Rows[cursorRow].Cells[cursorCol];
myGrid.CurrentCell = cell;
myGrid.BeginEdit(true);
单击可编辑单元格
可以,单击只读单元格
会出现异常错误:
错误-> 操作无效,因为它会导致对 SetCurrentCellAddressCore 函数的重入调用。
那么,这个问题有解决办法吗? (当用户点击ReadOnly Cell
时,光标将移动到Editable
Cell。)
编辑:我想要的解决方案是如何将光标移动到非当前单元格的其他单元格?
最佳答案
我已经找到了这个问题的解决方案here .
private void myGrid_CellEnter(object sender, DataGridViewCellEventArgs e)
{
//Do stuff
Application.Idle += new EventHandler(Application_Idle);
}
void Application_Idle(object sender, EventArgs e)
{
Application.Idle -= new EventHandler(Application_Idle);
myGrid.CurrentCell = myGrid[cursorCol,cursorRow];
}
关于c# - 更改DataGridView的Cell Enter事件中的当前单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14743857/