2008-04-16 Jonathan Pobst <monkey@jpobst.com>
authorJonathan Pobst <monkey@jpobst.com>
Wed, 16 Apr 2008 18:57:53 +0000 (18:57 -0000)
committerJonathan Pobst <monkey@jpobst.com>
Wed, 16 Apr 2008 18:57:53 +0000 (18:57 -0000)
* DataGridViewBand.cs: Add internal way to set displayed variable.
* DataGridViewRow.cs: Don't paint cells in non-displayed columns.
* DataGridView.cs: Make sure we always keep track of Displayed
rows and columns, and only draw things that are displayed.

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

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

index cf83f6e71813a440313ba3d11bed3c75246bdcd4..a8bb5278623a06dd26e761552b1e92f83303fac4 100644 (file)
@@ -1,3 +1,10 @@
+2008-04-16  Jonathan Pobst  <monkey@jpobst.com>
+
+       * DataGridViewBand.cs: Add internal way to set displayed variable.
+       * DataGridViewRow.cs: Don't paint cells in non-displayed columns.
+       * DataGridView.cs: Make sure we always keep track of Displayed
+       rows and columns, and only draw things that are displayed.
+
 2008-04-16  Atsushi Enomoto  <atsushi@ximian.com>
 
        * X11Keyboard.cs, XplatUIX11.cs : manage key state regardless of
index 4aa09021a4d8bad52d314ea714c7f120f0b12500..28b6745582bce28f1be0a1fb49cf71f01e4c4bd1 100644 (file)
@@ -1107,9 +1107,14 @@ namespace System.Windows.Forms {
                public DataGridViewSelectionMode SelectionMode {
                        get { return selectionMode; }
                        set {
-                               if (!Enum.IsDefined(typeof(DataGridViewSelectionMode), value)) {
-                                       throw new InvalidEnumArgumentException("Value is not valid DataGridViewSelectionMode.");
-                               }
+                               if (!Enum.IsDefined (typeof(DataGridViewSelectionMode), value))
+                                       throw new InvalidEnumArgumentException ("Value is not valid DataGridViewSelectionMode.");
+
+                               if (value == DataGridViewSelectionMode.ColumnHeaderSelect || value == DataGridViewSelectionMode.FullColumnSelect)
+                                       foreach (DataGridViewColumn col in Columns)
+                                               if (col.SortMode == DataGridViewColumnSortMode.Automatic)
+                                                       throw new InvalidOperationException (string.Format ("Cannot set SelectionMode to {0} because there are Automatic sort columns.", value));
+                               
                                selectionMode = value;
                        }
                }
@@ -2229,25 +2234,31 @@ namespace System.Windows.Forms {
                        return false;
                }
 
-               public int DisplayedColumnCount (bool includePartialColumns) {
-                       /////////////////////// PartialColumns?
+               [MonoTODO ("Always includes partial columns")]
+               public int DisplayedColumnCount (bool includePartialColumns)
+               {
                        int result = 0;
-                       foreach (DataGridViewColumn col in columns) {
-                               if (col.Visible) {
+                       
+                       for (int i = first_col_index; i < Columns.Count; i++)
+                               if ((Columns.ColumnDisplayIndexSortedArrayList[i] as DataGridViewColumn).Displayed)
                                        result++;
-                               }
-                       }
+                               else
+                                       break;
+
                        return result;
                }
 
-               public int DisplayedRowCount (bool includePartialRow) {
-                       /////////////////////// PartialRows?
+               [MonoTODO ("Always includes partial rows")]
+               public int DisplayedRowCount (bool includePartialRow)
+               {
                        int result = 0;
-                       foreach (DataGridViewRow row in rows) {
-                               if (row.Visible) {
+                       
+                       for (int i = first_row_index; i < Rows.Count; i++)
+                               if (Rows[i].Displayed)
                                        result++;
-                               }
-                       }
+                               else
+                                       break;
+                                       
                        return result;
                }
 
@@ -4128,16 +4139,37 @@ namespace System.Windows.Forms {
                                bounds.Y += columnHeadersHeight;
                        }
                        
-                       gridWidth = 0;
+                       gridWidth = rowHeadersVisible ? rowHeadersWidth : 0;
                        gridHeight = 0;
                        
                        int rows_displayed = 0;
                        int first_row_height = Rows.Count > 0 ? Rows[first_row_index].Height : 0;
+                       int room_left = this.Height;
+                       
+                       // Reset all columns to !Displayed
+                       for (int i = 0; i < Columns.Count; i++)
+                               Columns[i].DisplayedInternal = false;
+                       
+                       // Set Displayed columns
+                       for (int i = first_col_index; i < Columns.Count; i++) {
+                               DataGridViewColumn col = Columns.ColumnDisplayIndexSortedArrayList[i] as DataGridViewColumn;
+                               
+                               col.DisplayedInternal = true;
+                               gridWidth += col.Width;
+                               
+                               if (gridWidth >= Width)
+                                       break;
+                       }
+                       
+                       // Reset all rows to !Displayed
+                       for (int i = 0; i < Rows.Count; i++)
+                               GetRowInternal (i).DisplayedInternal = false;
                        
                        // Draw rows
                        for (int index = first_row_index; index < Rows.Count; index++) {
                                DataGridViewRow row = Rows[index];
-                               
+                               GetRowInternal (index).DisplayedInternal = true;
+       
                                bounds.Height = row.Height;
                                bool is_first = row.Index == 0;
                                bool is_last = row.Index == rows.Count - 1;
@@ -4154,6 +4186,8 @@ namespace System.Windows.Forms {
                                        
                                gridHeight += row.Height;
                        }
+
+                       gridWidth = 0;
                        
                        foreach (DataGridViewColumn col in sortedColumns)
                                gridWidth += col.Width;
@@ -4163,12 +4197,11 @@ namespace System.Windows.Forms {
                        foreach (DataGridViewRow row in Rows)
                                gridHeight += row.Height;
 
-                       if (rowHeadersVisible) {
+                       if (rowHeadersVisible)
                                gridWidth += rowHeadersWidth;
-                       }
-                       if (columnHeadersVisible) {
+
+                       if (columnHeadersVisible)
                                gridHeight += columnHeadersHeight;
-                       }
                        
                        bool horizontalVisible = false;
                        bool verticalVisible = false;
index 6339488c9eb496af400dee76560f1ba98e18cf2d..41523791904ad6716590de0a244a891da9bfc8cc 100644 (file)
@@ -154,6 +154,11 @@ namespace System.Windows.Forms {
                        }
                }
 
+               internal bool DisplayedInternal {
+                       get { return displayed; }
+                       set { displayed = value; }
+               }
+               
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public object Tag {
index 47f72b164b97d4a48e65fea8eb503ab2fe636667..b0942e419a3430852247c641ce2b5356520c6c4e 100644 (file)
@@ -513,6 +513,10 @@ namespace System.Windows.Forms
                        
                        for (int i = DataGridView.first_col_index; i < sortedColumns.Count; i++) {
                                DataGridViewColumn col = (DataGridViewColumn)sortedColumns[i];
+                               
+                               if (!col.Displayed)
+                                       break;
+                                       
                                bounds.Width = col.Width;
                                DataGridViewCell cell = Cells[col.Index];