1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
23 // Jordi Mas i Hernandez <jordi@ximian.com>
27 using System.Collections;
28 using System.ComponentModel;
30 namespace System.Windows.Forms
32 [Editor("System.Windows.Forms.Design.DataGridColumnCollectionEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
34 public class GridColumnStylesCollection : BaseCollection, IList
36 private ArrayList items;
37 private DataGridTableStyle owner;
38 private bool fire_event;
40 internal GridColumnStylesCollection (DataGridTableStyle tablestyle)
42 items = new ArrayList ();
47 #region Public Instance Properties
48 public DataGridColumnStyle this [string columnName] {
50 int idx = FromColumnNameToIndex (columnName);
51 return idx == -1 ? null : this [idx];
55 public DataGridColumnStyle this [int index] {
56 get { return (DataGridColumnStyle) items[index]; }
60 public DataGridColumnStyle this [PropertyDescriptor propDesc] {
62 for (int i = 0; i < items.Count; i++) {
63 DataGridColumnStyle column = (DataGridColumnStyle) items[i];
64 if (column.PropertyDescriptor.Equals (propDesc)) {
73 protected override ArrayList List {
77 int ICollection.Count {
78 get { return items.Count;}
81 bool ICollection.IsSynchronized {
85 object ICollection.SyncRoot {
89 bool IList.IsFixedSize {
93 bool IList.IsReadOnly {
97 object IList.this [int index] {
98 get { return items[index]; }
99 set { throw new NotSupportedException (); }
102 #endregion Public Instance Properties
104 #region Private Instance Properties
105 internal bool FireEvents {
106 get { return fire_event;}
107 set { fire_event = value;}
109 #endregion Private Instance Properties
111 #region Public Instance Methods
112 public virtual int Add (DataGridColumnStyle column)
114 // TODO: MS allows duplicate columns. How they diferenciate between them?
115 if (FromColumnNameToIndex (column.MappingName) != -1) {
116 throw new ArgumentException ("The ColumnStyles collection already has a column with this mapping name");
119 column.TableStyle = owner;
120 column.SetDataGridInternal (owner.DataGrid);
121 int cnt = items.Add (column);
122 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, column));
126 public void AddRange (DataGridColumnStyle[] columns)
128 foreach (DataGridColumnStyle mi in columns)
135 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh , null));
138 public bool Contains (DataGridColumnStyle column)
140 return (FromColumnNameToIndex (column.MappingName) != -1);
143 public bool Contains (PropertyDescriptor propDesc)
145 return (this [propDesc] != null);
148 public bool Contains (string name)
150 return (FromColumnNameToIndex (name) != -1);
153 void ICollection.CopyTo (Array dest, int index)
155 items.CopyTo (dest, index);
158 IEnumerator IEnumerable.GetEnumerator ()
160 return items.GetEnumerator ();
163 int IList.Add (object value)
165 return Add ((DataGridColumnStyle)value);
173 bool IList.Contains (object value)
175 return Contains ((DataGridColumnStyle)value);
178 int IList.IndexOf (object value)
180 return IndexOf ((DataGridColumnStyle)value);
183 void IList.Insert (int index, object value)
185 throw new NotSupportedException ();
188 void IList.Remove (object value)
190 Remove ((DataGridColumnStyle)value);
193 void IList.RemoveAt (int index)
198 public int IndexOf (DataGridColumnStyle element)
200 return items.IndexOf (element);
203 protected void OnCollectionChanged (CollectionChangeEventArgs ccevent)
205 if (fire_event == true && CollectionChanged != null) {
206 CollectionChanged (this, ccevent);
210 public void Remove (DataGridColumnStyle column)
212 items.Remove (column);
213 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, column));
216 public void RemoveAt (int index)
218 object item = items[index];
219 items.RemoveAt (index);
220 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, item));
223 public void ResetPropertyDescriptors ()
225 for (int i = 0; i < items.Count; i++) {
226 DataGridColumnStyle column = (DataGridColumnStyle) items[i];
227 if (column.PropertyDescriptor != null) {
228 column.PropertyDescriptor = null;
233 #endregion Public Instance Methods
236 public event CollectionChangeEventHandler CollectionChanged;
239 #region Private Instance Methods
240 private int FromColumnNameToIndex (string columnName)
242 for (int i = 0; i < items.Count; i++) {
243 DataGridColumnStyle column = (DataGridColumnStyle) items[i];
245 if (column.MappingName == null || column.MappingName == string.Empty)
248 if (String.Compare (column.MappingName, columnName, true) == 0) {
256 #endregion Private Instance Methods