CommitEdit()
方法没有达到我的预期)来实现“进入编辑模式”的简单概念,即双击单元格,修改其值(希望进行某种验证),并在离开前面提到的单元格时保存更改。我的实际代码看起来是这样的,它绝对是不完整的:
// DEBUG
private void myDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
this.myDataGridView.BeginEdit(true);
this.myDataGridView.CurrentCell.ReadOnly = false;
}
private void myDataGridView_CellLeave(object sender, DataGridViewCellEventArgs e)
{
this.myDataGridView.EndEdit();
}
private void myDataGridView_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
DataGridViewCellStyle editCellStyle = new DataGridViewCellStyle();
editCellStyle.BackColor = System.Drawing.Color.DarkOrange;
editCellStyle.ForeColor = System.Drawing.Color.Black;
this.myDataGridView.CurrentCell.Style.ApplyStyle(editCellStyle);
}
private void myDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
DataGridViewCellStyle defaultCellStyle = new DataGridViewCellStyle();
defaultCellStyle.BackColor = System.Drawing.Color.White;
this.myDataGridView.CurrentCell.Style.ApplyStyle(defaultCellStyle);
}
// DEBUG
所以,你可能会注意到,你所能提供的任何帮助都将是非常有价值的,并且非常感激。提前谢谢你们!