Merge pull request #439 from mono-soc-2012/garyb/iconfix
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridViewColumn.cs
index 5309811309838d9c718c2e0ce48bfb27cd5fdfd0..8b9e69b6c157849873fa8d90a0ddad4ae2e2cae7 100644 (file)
@@ -24,8 +24,6 @@
 //
 
 
-#if NET_2_0
-
 using System;
 using System.ComponentModel;
 
@@ -57,6 +55,7 @@ namespace System.Windows.Forms {
                private Type valueType;
                private bool visible = true;
                private int width = 100;
+               private int dataColumnIndex;
 
                private bool headerTextSet = false;
 
@@ -68,6 +67,7 @@ namespace System.Windows.Forms {
                        headerCell.SetColumnIndex(Index);
                        headerCell.Value = string.Empty;
                        displayIndex = -1;
+                       dataColumnIndex = -1;
                        dataPropertyName = string.Empty;
                        fillWeight = 100.0F;
                        sortMode = DataGridViewColumnSortMode.NotSortable;
@@ -100,12 +100,7 @@ namespace System.Windows.Forms {
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public virtual DataGridViewCell CellTemplate {
                        get { return cellTemplate; }
-                       set {
-                               cellTemplate = value;
-                               if (DataGridView != null) {
-                                       cellTemplate.SetDataGridView(DataGridView);
-                               }
-                       }
+                       set { cellTemplate = value; }
                }
 
                [Browsable (false)]
@@ -187,6 +182,20 @@ namespace System.Windows.Forms {
                        }
                }
 
+               internal int DisplayIndexInternal {
+                       get { return DisplayIndex; }
+                       set { displayIndex = value; }
+               }
+
+               internal int DataColumnIndex {
+                       get { return dataColumnIndex; }
+                       set { 
+                               dataColumnIndex = value;
+                               if (dataColumnIndex >= 0)
+                                       isDataBound = true;
+                       }
+               }
+
                [DefaultValue (0)]
                public int DividerWidth {
                        get { return dividerWidth; }
@@ -373,8 +382,13 @@ Example */
                public DataGridViewColumnSortMode SortMode {
                        get { return sortMode; }
                        set {
-                               if (value == DataGridViewColumnSortMode.Automatic && DataGridView != null && DataGridView.SelectionMode == DataGridViewSelectionMode.FullColumnSelect)
-                                       throw new InvalidOperationException ("Column's SortMode cannot be set to Automatic while the DataGridView control's SelectionMode is set to FullColumnSelect.");
+                               if (DataGridView != null && value == DataGridViewColumnSortMode.Automatic) {
+                                       if (DataGridView.SelectionMode == DataGridViewSelectionMode.FullColumnSelect ||
+                                           DataGridView.SelectionMode == DataGridViewSelectionMode.ColumnHeaderSelect)
+                                               throw new InvalidOperationException ("Column's SortMode cannot be set to Automatic "+
+                                                                                    "while the DataGridView control's SelectionMode "+
+                                                                                    "is set to FullColumnSelect or ColumnHeaderSelect.");
+                               }
 
                                if (sortMode != value) {
                                        sortMode = value;
@@ -414,7 +428,11 @@ Example */
                [Localizable (true)]
                public override bool Visible {
                        get { return visible; }
-                       set { visible = value; }
+                       set {
+                               visible = value;
+                               if (DataGridView != null)
+                                       DataGridView.Invalidate ();
+                       }
                }
 
                [Localizable (true)]
@@ -449,6 +467,7 @@ Example */
                        */
                }
 
+               [MonoTODO("Actually calculate width")]
                public virtual int GetPreferredWidth (DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight) {
                        switch (autoSizeColumnMode) {
                        case DataGridViewAutoSizeColumnMode.NotSet:
@@ -457,10 +476,10 @@ Example */
                                throw new ArgumentException("AutoSizeColumnMode is invalid");
                        }
                        if (fixedHeight) {
-                               return 0;
+                               return MinimumWidth;
                        }
                        else {
-                               return 0;
+                               return MinimumWidth;
                        }
                }
 
@@ -479,9 +498,6 @@ Example */
                        }
                        
                        base.SetDataGridView (dataGridView);
-                       if (cellTemplate != null) {
-                               cellTemplate.SetDataGridView(dataGridView);
-                       }
                        headerCell.SetDataGridView(dataGridView);
                }
 
@@ -490,11 +506,6 @@ Example */
                        headerCell.SetColumnIndex(Index);
                }
 
-               internal void SetIsDataBound (bool value)
-               {
-                       isDataBound = value;
-               }
-               
                internal override void SetState (DataGridViewElementStates state) {
                        if (State != state) {
                                base.SetState(state);
@@ -511,4 +522,3 @@ Example */
        }
 }
 
-#endif