2008-12-08 Ivan N. Zlatev <contact@i-nz.net>
authorIvan Zlatev <ivan@ivanz.com>
Mon, 8 Dec 2008 08:37:52 +0000 (08:37 -0000)
committerIvan Zlatev <ivan@ivanz.com>
Mon, 8 Dec 2008 08:37:52 +0000 (08:37 -0000)
* DataGridView.cs: EndEdit validation fixes.

svn path=/trunk/mcs/; revision=120984

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs

index 04056083e88aa1ae0b157bc11693508042b08f38..026236f86beddc6de73f816b5450b2fbe2a6179b 100644 (file)
@@ -1,3 +1,7 @@
+2008-12-08  Ivan N. Zlatev  <contact@i-nz.net>
+
+       * DataGridView.cs: EndEdit validation fixes.
+
 2008-12-08  Ivan N. Zlatev  <contact@i-nz.net>
 
        * DataGridView.cs: This is the cool patch that adds support for 
index 39b94c1b7cfb5992d307eae911ae204060c1e48d..3f766d3eb01f01c462da2825d4cb66a9a6656b20 100644 (file)
@@ -2232,7 +2232,7 @@ namespace System.Windows.Forms {
                public virtual bool BeginEdit (bool selectAll) {
                        if (currentCell == null || currentCell.IsInEditMode)
                                return false;
-                       
+
                        if (currentCell.RowIndex >= 0) {
                                if ((currentCell.InheritedState & DataGridViewElementStates.ReadOnly) == DataGridViewElementStates.ReadOnly) {
                                        return false;
@@ -2354,10 +2354,12 @@ namespace System.Windows.Forms {
                                                InternalOnDataError (args);
                                                if (args.ThrowException)
                                                        throw exc;
+                                               return false;
                                        }
                                }
                        }
-                       return false;
+
+                       return true;
                }
 
                [MonoTODO ("Always includes partial columns")]
@@ -2405,24 +2407,26 @@ namespace System.Windows.Forms {
                [MonoTODO ("Does not use context parameter")]
                public bool EndEdit (DataGridViewDataErrorContexts context)
                {
-                       if (currentCell != null && currentCell.IsInEditMode) {
-                               if (!CommitEdit (context))
-                                       return false;
+                       if (currentCell == null || !currentCell.IsInEditMode)
+                               return true;
 
-                               if (EditingControl != null) {
-                                       IDataGridViewEditingControl ctrl = EditingControl as IDataGridViewEditingControl;
-                                       currentCell.Value = ctrl.GetEditingControlFormattedValue (DataGridViewDataErrorContexts.Commit);
-                                       currentCell.SetIsInEditMode (false);
-                                       currentCell.DetachEditingControl ();    
-                               } else if (currentCell is IDataGridViewEditingCell) {
-                                       currentCell.Value = (currentCell as IDataGridViewEditingCell).EditingCellFormattedValue;
-                                       currentCell.SetIsInEditMode (false);
+                       if (EditingControl != null) {
+                               IDataGridViewEditingControl ctrl = EditingControl as IDataGridViewEditingControl;
+                               currentCell.Value = ctrl.GetEditingControlFormattedValue (DataGridViewDataErrorContexts.Commit);
+                               if (!CommitEdit (context)) {
+                                       EditingControl.Focus ();
+                                       return false;
                                }
-
-                               new_row_commited = true;
-                               OnCellEndEdit (new DataGridViewCellEventArgs (currentCell.ColumnIndex, currentCell.RowIndex));
+                               currentCell.DetachEditingControl ();    
+                       } else if (currentCell is IDataGridViewEditingCell) {
+                               currentCell.Value = (currentCell as IDataGridViewEditingCell).EditingCellFormattedValue;
+                               if (!CommitEdit (context))
+                                       return false;
                        }
-                       
+
+                       currentCell.SetIsInEditMode (false);
+                       new_row_commited = true;
+                       OnCellEndEdit (new DataGridViewCellEventArgs (currentCell.ColumnIndex, currentCell.RowIndex));
                        Focus ();
                        return true;
                }
@@ -4192,6 +4196,9 @@ namespace System.Windows.Forms {
                {
                        base.OnMouseDown(e);
                        
+                       if (!EndEdit ())
+                               return;
+
                        HitTestInfo hitTest = HitTest(e.X, e.Y);
                        
                        DataGridViewCell cell = null;
@@ -4199,8 +4206,6 @@ namespace System.Windows.Forms {
                        Rectangle cellBounds;
 
                        if (hitTest.Type == DataGridViewHitTestType.ColumnHeader && MouseOverColumnResize (hitTest.ColumnIndex, e.X)) {
-                               if (!EndEdit())
-                                       return;
                                if (e.Clicks == 2) {
                                        AutoResizeColumn (hitTest.ColumnIndex);
                                        return;
@@ -4215,8 +4220,6 @@ namespace System.Windows.Forms {
                        }
 
                        if (hitTest.Type == DataGridViewHitTestType.RowHeader && MouseOverRowResize (hitTest.RowIndex, e.Y)) {
-                               if (!EndEdit())
-                                       return;
                                if (e.Clicks == 2) {
                                        AutoResizeRow (hitTest.RowIndex);
                                        return;
@@ -5368,18 +5371,17 @@ namespace System.Windows.Forms {
                        if (cell != null && !cell.Visible)
                                throw new InvalidOperationException ("cell is not visible");
                                
-                       if (setAnchorCellAddress)
-                               anchor_cell = new Point (columnIndex, rowIndex);
-
                        if (cell != currentCell) {
                                if (currentCell != null) {
-                                       if (currentCell.IsInEditMode)
-                                               EndEdit ();
+                                       if (currentCell.IsInEditMode && !EndEdit ())
+                                               return false;
                                        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);
 
                                UpdateBindingPosition (currentCell.RowIndex);
@@ -5960,7 +5962,8 @@ namespace System.Windows.Forms {
 
                private void MoveCurrentCell (int x, int y, bool select, bool isControl, bool isShift, bool scroll)
                {
-                       SetCurrentCellAddressCore (x, y, true, false, false);
+                       if (!SetCurrentCellAddressCore (x, y, true, false, false))
+                               return;
 
                        bool full_row_selected = Rows.SharedRow(CurrentCellAddress.Y).Selected;
                        bool full_col_selected = Columns[CurrentCellAddress.X].Selected;