* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / GridColumnStylesCollection.cs
index d7bec64fa91cf5708ecffb29e8f20f3c34a9ebd2..daebdca016cfe69f6809dab7d1dfe9641f2f473e 100644 (file)
@@ -53,9 +53,7 @@ namespace System.Windows.Forms
                }
 
                public DataGridColumnStyle this [int index] {
-                       get {
-                               return (DataGridColumnStyle) items[index];
-                       }
+                       get { return (DataGridColumnStyle) items[index]; }
                }
 
                
@@ -85,7 +83,7 @@ namespace System.Windows.Forms
                }
 
                object ICollection.SyncRoot {
-                       get { return this;}
+                       get { return this; }
                }
 
                bool IList.IsFixedSize {
@@ -93,16 +91,12 @@ namespace System.Windows.Forms
                }
 
                bool IList.IsReadOnly {
-                       get { return false;}
+                       get { return false; }
                }
 
                object IList.this [int index] {
-                       get {
-                               return items[index];
-                       }
-                       set {
-                               throw new NotSupportedException ();
-                       }
+                       get { return items[index]; }
+                       set { throw new NotSupportedException (); }
                }
 
                #endregion Public Instance Properties
@@ -117,17 +111,22 @@ namespace System.Windows.Forms
                #region Public Instance Methods
                public virtual int Add (DataGridColumnStyle column)
                {
-                       int cnt = AddInternal (column);
+                       // TODO: MS allows duplicate columns. How they diferenciate between them?
+                       if (FromColumnNameToIndex (column.MappingName) != -1) {
+                               throw new ArgumentException ("The ColumnStyles collection already has a column with this mapping name");
+                       }
+                       
+                       column.TableStyle = owner;
+                       column.SetDataGridInternal (owner.DataGrid);
+                       int cnt = items.Add (column);
                        OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, column));
-                       return cnt;
+                       return cnt;                     
                }
 
                public void AddRange (DataGridColumnStyle[] columns)
                {
                        foreach (DataGridColumnStyle mi in columns)
-                               AddInternal (mi);
-
-                       OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh, null));
+                               Add (mi);                       
                }
 
                public void Clear ()
@@ -163,26 +162,22 @@ namespace System.Windows.Forms
 
                int IList.Add (object value)
                {
-                       int cnt = AddInternal ((DataGridColumnStyle)value);
-
-                       OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, null));
-                       return cnt;
+                       return Add ((DataGridColumnStyle)value);                        
                }
 
                void IList.Clear ()
                {
-                       items.Clear ();
-                       OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh , null));
+                       Clear ();
                }
 
                bool IList.Contains (object value)
                {
-                       return items.Contains (value);
+                       return Contains ((DataGridColumnStyle)value);
                }
 
                int IList.IndexOf (object value)
                {
-                       return items.IndexOf (value);
+                       return IndexOf ((DataGridColumnStyle)value);
                }
 
                void IList.Insert (int index, object value)
@@ -192,15 +187,12 @@ namespace System.Windows.Forms
 
                void IList.Remove (object value)
                {
-                       items.Remove (value);
+                       Remove ((DataGridColumnStyle)value);
                }
 
                void IList.RemoveAt (int index)
                {
-                       object item = items[index];
-                       
-                       items.RemoveAt (index);
-                       OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, item));
+                       RemoveAt (index);
                }
                
                public int IndexOf (DataGridColumnStyle element)
@@ -245,23 +237,12 @@ namespace System.Windows.Forms
                #endregion Events               
                
                #region Private Instance Methods
-               private int AddInternal (DataGridColumnStyle column)
-               {                               
-                       if (FromColumnNameToIndex (column.MappingName) != -1) {
-                               throw new ArgumentException ("The ColumnStyles collection already has a column with this mapping name");
-                       }
-                       
-                       column.TableStyle = owner;
-                       int cnt = items.Add (column);
-                       return cnt;                     
-               }
-               
                private int FromColumnNameToIndex (string columnName)
                {       
                        for (int i = 0; i < items.Count; i++) {
                                DataGridColumnStyle column = (DataGridColumnStyle) items[i];
-
-                               if (column.MappingName == null)
+                               
+                               if (column.MappingName == null || column.MappingName == string.Empty)
                                        continue;
 
                                if (String.Compare (column.MappingName, columnName, true) == 0) {