Я едва знаком с элементом управления WinGorm DataGridView и, честно говоря, мне трудно пытаться смешивать и сопоставлять его события и методы (например, метод 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
Так что, как вы могли заметить, любая помощь, которую вы могли бы оказать, будет действительно ценной и, безусловно, ценной. Большое спасибо вам, ребята, заранее!