+ // Always update the current cell address property
+ // If the row has moved it would be out of date.
+ if (currentCell != null) {
+ if (setAnchorCellAddress) {
+ anchor_cell.X = currentCell.ColumnIndex;
+ anchor_cell.Y = currentCell.RowIndex;
+ }
+ currentCellAddress.X = currentCell.ColumnIndex;
+ currentCellAddress.Y = currentCell.RowIndex;
+ }
+
+ if (cell != currentCell) {
+ if (currentCell != null) {
+ if (currentCell.IsInEditMode) {
+ if (!EndEdit ())
+ return false;
+ else if (currentCell.RowIndex == NewRowIndex && new_row_editing)
+ CancelEdit ();
+ }
+ OnCellLeave (new DataGridViewCellEventArgs(currentCell.ColumnIndex, currentCell.RowIndex));
+ OnRowLeave (new DataGridViewCellEventArgs (currentCell.ColumnIndex, currentCell.RowIndex));
+ }
+
+ currentCell = cell;
+ if (setAnchorCellAddress)
+ anchor_cell = new Point (columnIndex, rowIndex);
+ currentCellAddress = new Point (columnIndex, rowIndex);
+
+ if (cell != null) {
+ UpdateBindingPosition (cell.RowIndex);
+ OnRowEnter (new DataGridViewCellEventArgs (cell.ColumnIndex, cell.RowIndex));
+ OnCellEnter (new DataGridViewCellEventArgs(cell.ColumnIndex, cell.RowIndex));
+ }
+ OnCurrentCellChanged (EventArgs.Empty);
+
+ if (cell != null) {
+ // If the user begins an edit in the NewRow, add a new row
+ if (AllowUserToAddRows && cell.RowIndex == NewRowIndex && !is_binding && !new_row_editing) {
+ // OnUserAddedRow will add a real row and reset the current cell
+ OnUserAddedRow (new DataGridViewRowEventArgs (Rows[NewRowIndex]));
+ } else {
+ if (editMode == DataGridViewEditMode.EditOnEnter)
+ BeginEdit (true);
+ }
+ }
+ } else {
+ if (cell != null && throughMouseClick)
+ BeginEdit (true);
+ }