protected override void OnCellEndEdit(DataGridViewCellEventArgs e) { String nowText = this.CurrentCell.Value as String; CellTextChangedEventArgs args = new CellTextChangedEventArgs(BeforeText, nowText, Now.Col, Now.Row, this.Rows[Now.Row], this.Rows[Now.Row].Cells[Now.Col] as DataGridViewTextBoxCell); if (_isEditActivated) { if (BeforeText.Equals(nowText) == false) { if (E_TextChanged != null) { E_TextChanged(this, args); } if (args.IsCancel) { if (EditingControl != null) { this.EditingControl.Text = BeforeText; } Cell(Now).Value = BeforeText; } } if (E_TextEditFinished != null) { E_TextEditFinished(this, args); } _isEditActivated = false; } base.OnCellEndEdit(e); }
/* * protected override void OnCellMouseClick(DataGridViewCellMouseEventArgs e) * { * try * { * if (e.RowIndex >= 0 && e.ColumnIndex >= 0) * { * Now.Set(e.RowIndex, e.ColumnIndex); * if (Before.Col >= 0 && Before.Row >= 0) * { * * this.Rows[Before.Row].Cells[Before.Col].Selected = false; * } * Before.Set(Now); * this.CurrentCell = this.Rows[e.RowIndex].Cells[e.ColumnIndex]; * this.CurrentCell.Selected = true; * } * } * catch { } * base.OnCellMouseClick(e); * } */ protected override void OnCellLeave(DataGridViewCellEventArgs e) {//cell을 떠나는 경우는 CurrentCell이 있는 경우이다. //있을 수 있는경우의 수는, 세 가지이다. //마우스로 인하여 이전에서 옮겨지는 경우, Before가 의미가 없어진다. //키보드의 방향키로 인해 위치가 옮겨지는 경우, 역시 Before의 의미가 없다. //Enter로 그 자신의 위치로 다시 옮겨지는 경우에만 Before가 의미가 있다. if (_goBack) { Before.Set(e.RowIndex, e.ColumnIndex); } if (this.EditingControl != null && _isEditActivated) //편집모드였다가 나갈 때는 값이 갱신되었다면 이벤트를 호출시킨다. { String nowText = this.EditingControl.Text.ToString(); // this.CurrentCell.Value.ToString(); this.CurrentCell.Value = nowText; if (_isEditActivated) { CellTextChangedEventArgs args = new CellTextChangedEventArgs(BeforeText, nowText, Before.Col, Before.Row, this.Rows[Before.Row], this.Rows[Before.Row].Cells[Before.Col] as DataGridViewTextBoxCell); if (BeforeText.Equals(nowText) == false) { if (E_TextChanged != null) { E_TextChanged(this, args); } if (args.IsCancel) { this.EditingControl.Text = BeforeText; } } if (E_TextEditFinished != null) { E_TextEditFinished(this, args); } _isEditActivated = false; } } /* * if (this.EditingControl == null && _isEditing) * { * if (ActionOnEnterInEditMode == EnterActions.EditNextColumn) * { * * } * else if (ActionOnEnterInEditMode == EnterActions.EditNextRow) * { * } * else //ActionOnEnterInEditMode == EnterActions.EditOnThePosition * { * * return; * } * } */ /* * if (Now.Row >= 0 && Now.Col >= 0) * { * * if (this.CurrentCell!=null && this.CurrentCell is DataGridViewTextBoxCell) * { * if (_isEditing && this.EditingControl!=null) * { * String nowText = this.EditingControl.Text.ToString();// this.CurrentCell.Value.ToString(); * this.CurrentCell.Value = nowText; * if (_isEditActivated) * { * CellTextChangedEventArgs args = new CellTextChangedEventArgs(BeforeText, nowText, Before.Col, Before.Row, this.Rows[Before.Row], this.Rows[Before.Row].Cells[Before.Col] as DataGridViewTextBoxCell); * if (BeforeText.Equals(nowText) == false) * { * if (E_TextChanged != null) E_TextChanged(this, args); * * } * if (E_TextEditFinished != null) E_TextEditFinished(this, args); * _isEditActivated = false; * } * } * } * if(_posAfterEdit!=_posAfterEdit) Before.Set(Now); * * } * else * { * Before.Set(e.RowIndex, e.ColumnIndex); * } */ base.OnCellLeave(e); }