[MWF] Fix crash when setting Row.Height (Fixes #2394)
authorEberhard Beilharz <eb1@sil.org>
Mon, 10 Mar 2014 17:32:54 +0000 (18:32 +0100)
committerEberhard Beilharz <eb1@sil.org>
Wed, 12 Mar 2014 15:45:43 +0000 (16:45 +0100)
When setting both Row.Height and MinimumHeight we need to set the
MinimumHeight first otherwise we will get a crash if the new Height
value is less than the old MinimumHeight value.

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

index 67227b683a82d1d2bd718b7151f4ea216926197b..b7e9a1d853cb456c67a5d120212da058499b7f4c 100644 (file)
@@ -3140,6 +3140,20 @@ namespace System.Windows.Forms {
                                InvalidateRow (i);
                }
 
+               private void UpdateRowHeightInfo (DataGridViewRow row)
+               {
+                       DataGridViewRowHeightInfoNeededEventArgs rowInfo =
+                               new DataGridViewRowHeightInfoNeededEventArgs (row.Index, row.Height, row.MinimumHeight);
+                       OnRowHeightInfoNeeded (rowInfo);
+
+                       if (row.Height != rowInfo.Height || row.MinimumHeight != rowInfo.MinimumHeight) {
+                               row.MinimumHeight = rowInfo.MinimumHeight;
+                               row.Height = rowInfo.Height;
+                               OnRowHeightInfoPushed (new DataGridViewRowHeightInfoPushedEventArgs (row.Index, rowInfo.Height,
+                                                                                                       rowInfo.MinimumHeight));
+                       }
+               }
+
                public void UpdateRowHeightInfo (int rowIndex, bool updateToEnd)
                {
                        if (rowIndex < 0 && updateToEnd)
@@ -3159,33 +3173,12 @@ namespace System.Windows.Forms {
 
                        if (updateToEnd) {
                                for (int i = rowIndex; i < Rows.Count; i++) {
-                                       DataGridViewRow row = Rows[i];
-                                       if (!row.Visible)
-                                               continue;
-
-                                       DataGridViewRowHeightInfoNeededEventArgs rowInfo = 
-                                               new DataGridViewRowHeightInfoNeededEventArgs (row.Index, row.Height, row.MinimumHeight);
-                                       OnRowHeightInfoNeeded (rowInfo);
-
-                                       if (row.Height != rowInfo.Height || row.MinimumHeight != rowInfo.MinimumHeight) {
-                                               row.Height = rowInfo.Height;
-                                               row.MinimumHeight = rowInfo.MinimumHeight;
-                                               OnRowHeightInfoPushed (new DataGridViewRowHeightInfoPushedEventArgs (row.Index, rowInfo.Height, 
-                                                                                                                    rowInfo.MinimumHeight));
-                                       }
+                                       DataGridViewRow row = Rows [i];
+                                       if (row.Visible)
+                                               UpdateRowHeightInfo (row);
                                }
                        } else {
-                               DataGridViewRow row = Rows[rowIndex];
-                               DataGridViewRowHeightInfoNeededEventArgs rowInfo = 
-                                       new DataGridViewRowHeightInfoNeededEventArgs (row.Index, row.Height, row.MinimumHeight);
-                               OnRowHeightInfoNeeded (rowInfo);
-
-                               if (row.Height != rowInfo.Height || row.MinimumHeight != rowInfo.MinimumHeight) {
-                                       row.Height = rowInfo.Height;
-                                       row.MinimumHeight = rowInfo.MinimumHeight;
-                                       OnRowHeightInfoPushed (new DataGridViewRowHeightInfoPushedEventArgs (row.Index, rowInfo.Height, 
-                                                                                                            rowInfo.MinimumHeight));
-                               }
+                               UpdateRowHeightInfo (Rows [rowIndex]);
                        }
                }