我试图DataGridViewCell
仅在选择模式而不是在 C# 中的编辑模式中检测离开事件。那就是下面给出的代码在这里显示:
private void dgv_CellLeave(object sender, DataGridViewCellEventArgs e)
{
if (dgvC.CurrentCell.ColumnIndex == 0)
{
if (dgv.CurrentCell.Value == null)
MessageBox.Show("You have to enter somthing");
}
}
private void dgv_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (dgv.CurrentCell.ColumnIndex == 0)
{
if (dgv.CurrentCell.Value.ToString() !="S" )
MessageBox.Show("You have to enter S");
}
}
当我选择网格单元格时,上述事件正常工作,但在编辑单元格时它们不起作用。意味着在这两种情况下都发生了休假事件。所以我想检测当前单元格是否处于编辑模式或选择模式,之后我必须将光标放在同一个单元格中,不应更改。谁能告诉我该怎么做?