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
33 public class GridTableStylesCollection
: BaseCollection
, IList
35 private ArrayList items
;
36 private DataGrid owner
;
38 internal GridTableStylesCollection (DataGrid grid
)
40 items
= new ArrayList ();
44 #region Public Instance Properties
45 public DataGridTableStyle
this[string tableName
] {
47 int idx
= FromTableNameToIndex (tableName
);
48 return idx
== -1 ? null : this [idx
];
52 public DataGridTableStyle
this[int index
] {
54 return (DataGridTableStyle
) items
[index
];
58 protected override ArrayList List
{
62 int ICollection
.Count
{
63 get { return items.Count;}
66 bool ICollection
.IsSynchronized
{
70 object ICollection
.SyncRoot
{
74 bool IList
.IsFixedSize
{
78 bool IList
.IsReadOnly
{
82 object IList
.this [int index
] {
87 throw new NotSupportedException ();
91 #endregion Public Instance Properties
93 #region Public Instance Methods
94 public virtual int Add (DataGridTableStyle table
)
96 int cnt
= AddInternal (table
);
97 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction
.Add
, table
));
101 public virtual void AddRange (DataGridTableStyle
[] tables
)
103 foreach (DataGridTableStyle mi
in tables
)
106 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction
.Refresh
, null));
112 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction
.Refresh
, null));
115 public bool Contains (DataGridTableStyle table
)
117 return (FromTableNameToIndex (table
.MappingName
) != -1);
120 public bool Contains (string name
)
122 return (FromTableNameToIndex (name
) != -1);
125 void ICollection
.CopyTo (Array dest
, int index
)
127 items
.CopyTo (dest
, index
);
130 IEnumerator IEnumerable
.GetEnumerator ()
132 return items
.GetEnumerator ();
135 int IList
.Add (object value)
137 return Add ((DataGridTableStyle
)value);
145 bool IList
.Contains (object value)
147 return Contains ((DataGridTableStyle
) value);
150 int IList
.IndexOf (object value)
152 return items
.IndexOf (value);
155 void IList
.Insert (int index
, object value)
157 throw new NotSupportedException ();
160 void IList
.Remove (object value)
162 Remove ((DataGridTableStyle
) value);
165 void IList
.RemoveAt (int index
)
170 protected void OnCollectionChanged (CollectionChangeEventArgs ccevent
)
172 if (CollectionChanged
!= null) {
173 CollectionChanged (this, ccevent
);
177 public void Remove (DataGridTableStyle table
)
179 items
.Remove (table
);
180 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction
.Remove
, table
));
183 void MappingNameChanged (object sender
, EventArgs args
)
185 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction
.Refresh
, null));
188 public void RemoveAt (int index
)
190 DataGridTableStyle style
= (DataGridTableStyle
)items
[index
];
192 items
.RemoveAt (index
);
193 style
.MappingNameChanged
-= new EventHandler (MappingNameChanged
);
194 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction
.Remove
, style
));
197 #endregion Public Instance Methods
200 public event CollectionChangeEventHandler CollectionChanged
;
204 #region Private Instance Methods
205 private int AddInternal (DataGridTableStyle table
)
207 // TODO: MS allows duplicate columns. How they diferenciate between them?
208 if (FromTableNameToIndex (table
.MappingName
) != -1) {
209 throw new ArgumentException ("The TableStyles collection already has a TableStyle with this mapping name");
212 table
.MappingNameChanged
+= new EventHandler (MappingNameChanged
);
213 table
.DataGrid
= owner
;
214 int cnt
= items
.Add (table
);
218 private int FromTableNameToIndex (string tableName
)
220 for (int i
= 0; i
< items
.Count
; i
++) {
221 DataGridTableStyle table
= (DataGridTableStyle
) items
[i
];
223 if (String
.Compare (table
.MappingName
, tableName
, true) == 0) {
231 #endregion Private Instance Methods