3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * Namespace: System.Web.UI.WebControls
\r
24 * Class: DataGridColumnCollection
\r
26 * Author: Gaurav Vaish
\r
27 * Maintainer: gvaish@iitk.ac.in
\r
28 * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>
\r
29 * Implementation: yes
\r
32 * (C) Gaurav Vaish (2002)
\r
36 using System.ComponentModel;
\r
37 using System.Collections;
\r
39 using System.Web.UI;
\r
41 namespace System.Web.UI.WebControls
\r
43 public sealed class DataGridColumnCollection : ICollection, IEnumerable, IStateManager
\r
45 private DataGrid owner;
\r
46 private ArrayList columns;
\r
47 private bool trackViewState;
\r
49 public DataGridColumnCollection(DataGrid owner, ArrayList columns)
\r
52 this.columns = columns;
\r
60 return columns.Count;
\r
65 public bool IsReadOnly
\r
74 public bool IsSynchronized
\r
83 public DataGridColumn this[int index]
\r
87 return (DataGridColumn)(columns[index]);
\r
92 public object SyncRoot
\r
100 public void Add(DataGridColumn column)
\r
105 public void AddAt(int index, DataGridColumn column)
\r
109 columns.Add(column);
\r
112 columns.Insert(index, column);
\r
115 column.SetOwner (owner);
\r
118 ((IStateManager)column).TrackViewState();
\r
120 OnColumnsChanged();
\r
123 internal void OnColumnsChanged()
\r
127 owner.OnColumnsChanged();
\r
131 public void Clear()
\r
134 OnColumnsChanged();
\r
137 public void CopyTo(Array array, int index)
\r
139 foreach(DataGridColumn current in this)
\r
141 array.SetValue(current, index++);
\r
145 public IEnumerator GetEnumerator()
\r
147 return columns.GetEnumerator();
\r
150 public int IndexOf(DataGridColumn column)
\r
154 return columns.IndexOf(column);
\r
159 public void Remove(DataGridColumn column)
\r
163 RemoveAt(IndexOf(column));
\r
167 public void RemoveAt(int index)
\r
169 if(index >= 0 && index < columns.Count)
\r
171 columns.RemoveAt(index);
\r
172 OnColumnsChanged();
\r
175 //This exception is not documented, but thrown
\r
176 throw new ArgumentOutOfRangeException("string");
\r
179 object IStateManager.SaveViewState()
\r
181 if (columns.Count == 0)
\r
184 ArrayList retVal = new ArrayList (columns.Count);
185 bool found = false;
\r
186 foreach (IStateManager current in columns) {
187 object o = current.SaveViewState ();
\r
199 void IStateManager.LoadViewState(object savedState)
\r
201 if (savedState == null || !(savedState is ArrayList))
\r
204 ArrayList list = (ArrayList) savedState;
\r
205 int end = list.Count;
\r
206 if (end != columns.Count)
\r
209 for (int i = 0; i < end; i++) {
\r
210 IStateManager col = (IStateManager) columns [i];
\r
211 col.LoadViewState (list [i]);
\r
215 void IStateManager.TrackViewState()
217 trackViewState = true;
218 foreach (IStateManager col in columns)
219 col.TrackViewState ();
222 bool IStateManager.IsTrackingViewState
\r
226 return trackViewState;
\r