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 public class GridColumnStylesCollection : BaseCollection, IList
34 private ArrayList items;
35 private DataGridTableStyle owner;
36 private bool fire_event;
38 internal GridColumnStylesCollection (DataGridTableStyle tablestyle)
40 items = new ArrayList ();
45 #region Public Instance Properties
46 public DataGridColumnStyle this [string columnName] {
48 int idx = FromColumnNameToIndex (columnName);
49 return idx == -1 ? null : this [idx];
53 public DataGridColumnStyle this [int index] {
55 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] {
102 throw new NotSupportedException ();
106 #endregion Public Instance Properties
108 #region Private Instance Properties
109 internal bool FireEvents {
110 get { return fire_event;}
111 set { fire_event = value;}
113 #endregion Private Instance Properties
115 #region Public Instance Methods
116 public virtual int Add (DataGridColumnStyle column)
118 int cnt = AddInternal (column);
119 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, column));
123 public void AddRange (DataGridColumnStyle[] columns)
125 foreach (DataGridColumnStyle mi in columns)
128 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh, null));
134 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh , null));
137 public bool Contains (DataGridColumnStyle column)
139 return items.Contains (column);
143 public bool Contains (PropertyDescriptor propDesc)
145 return (this [propDesc] != null);
148 public bool Contains (string name)
150 return (this[name] != null);
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 int cnt = AddInternal ((DataGridColumnStyle)value);
167 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, null));
174 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh , null));
177 bool IList.Contains (object value)
179 return items.Contains (value);
182 int IList.IndexOf (object value)
184 return items.IndexOf (value);
187 void IList.Insert (int index, object value)
189 throw new NotSupportedException ();
192 void IList.Remove (object value)
194 items.Remove (value);
197 void IList.RemoveAt (int index)
199 object item = items[index];
201 items.RemoveAt (index);
202 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, item));
205 public int IndexOf (DataGridColumnStyle element)
207 return items.IndexOf (element);
210 protected void OnCollectionChanged (CollectionChangeEventArgs ccevent)
212 if (fire_event == true && CollectionChanged != null) {
213 CollectionChanged (this, ccevent);
217 public void Remove (DataGridColumnStyle column)
219 items.Remove (column);
220 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, column));
223 public void RemoveAt (int index)
225 object item = items[index];
226 items.RemoveAt (index);
227 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, item));
230 public void ResetPropertyDescriptors ()
232 for (int i = 0; i < items.Count; i++) {
233 DataGridColumnStyle column = (DataGridColumnStyle) items[i];
234 if (column.PropertyDescriptor != null) {
235 column.PropertyDescriptor = null;
240 #endregion Public Instance Methods
243 public event CollectionChangeEventHandler CollectionChanged;
246 #region Private Instance Methods
247 private int AddInternal (DataGridColumnStyle column)
249 if (FromColumnNameToIndex (column.MappingName) != -1) {
250 throw new ArgumentException ("The ColumnStyles collection already has a column with this mapping name");
253 column.TableStyle = owner;
254 int cnt = items.Add (column);
258 private int FromColumnNameToIndex (string columnName)
260 for (int i = 0; i < items.Count; i++) {
261 DataGridColumnStyle column = (DataGridColumnStyle) items[i];
262 if (column.MappingName == columnName) {
270 #endregion Private Instance Methods