1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
//------------------------------------------------------------------------------
// <copyright file="ColumnCollection.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.WebControls {
using System;
using System.Collections;
using System.ComponentModel;
using System.Web.UI;
/// <devdoc>
/// <para>Represents the collection of columns to be displayed in
/// a <see cref='System.Web.UI.WebControls.DataGrid'/>
/// control.</para>
/// </devdoc>
public sealed class DataGridColumnCollection : ICollection, IStateManager {
private DataGrid owner;
private ArrayList columns;
private bool marked;
/// <devdoc>
/// <para>Initializes a new instance of <see cref='System.Web.UI.WebControls.DataGridColumnCollection'/> class.</para>
/// </devdoc>
public DataGridColumnCollection(DataGrid owner, ArrayList columns) {
this.owner = owner;
this.columns = columns;
}
/// <devdoc>
/// <para>Gets the number of columns in the collection. This property is read-only.</para>
/// </devdoc>
[
Browsable(false)
]
public int Count {
get {
return columns.Count;
}
}
/// <devdoc>
/// <para>Gets a value that specifies whether items in the <see cref='System.Web.UI.WebControls.DataGridColumnCollection'/> can be
/// modified. This property is read-only.</para>
/// </devdoc>
[
Browsable(false)
]
public bool IsReadOnly {
get {
return false;
}
}
/// <devdoc>
/// <para>Gets a value that indicates whether the <see cref='System.Web.UI.WebControls.DataGridColumnCollection'/> is thread-safe. This property is read-only.</para>
/// </devdoc>
[
Browsable(false)
]
public bool IsSynchronized {
get {
return false;
}
}
/// <devdoc>
/// <para>Gets the object used to synchronize access to the collection. This property is read-only. </para>
/// </devdoc>
[
Browsable(false)
]
public Object SyncRoot {
get {
return this;
}
}
/// <devdoc>
/// <para>Gets a <see cref='System.Web.UI.WebControls.DataGridColumn'/> at the specified index in the
/// collection.</para>
/// </devdoc>
[
Browsable(false)
]
public DataGridColumn this[int index] {
get {
return (DataGridColumn)columns[index];
}
}
/// <devdoc>
/// <para>Appends a <see cref='System.Web.UI.WebControls.DataGridColumn'/> to the collection.</para>
/// </devdoc>
public void Add(DataGridColumn column) {
AddAt(-1, column);
}
/// <devdoc>
/// <para>Inserts a <see cref='System.Web.UI.WebControls.DataGridColumn'/> to the collection
/// at the specified index.</para>
/// </devdoc>
public void AddAt(int index, DataGridColumn column) {
if (column == null) {
throw new ArgumentNullException("column");
}
if (index == -1) {
columns.Add(column);
}
else {
columns.Insert(index, column);
}
column.SetOwner(owner);
if (marked)
((IStateManager)column).TrackViewState();
OnColumnsChanged();
}
/// <devdoc>
/// <para>Empties the collection of all <see cref='System.Web.UI.WebControls.DataGridColumn'/> objects.</para>
/// </devdoc>
public void Clear() {
columns.Clear();
OnColumnsChanged();
}
/// <devdoc>
/// <para>Copies the contents of the entire collection into an <see cref='System.Array' qualify='true'/> appending at
/// the specified index of the <see cref='System.Array' qualify='true'/>.</para>
/// </devdoc>
public void CopyTo(Array array, int index) {
if (array == null) {
throw new ArgumentNullException("array");
}
for (IEnumerator e = this.GetEnumerator(); e.MoveNext();)
array.SetValue(e.Current, index++);
}
/// <devdoc>
/// <para>Creates an enumerator for the <see cref='System.Web.UI.WebControls.DataGridColumnCollection'/> used to iterate through the collection.</para>
/// </devdoc>
public IEnumerator GetEnumerator() {
return columns.GetEnumerator();
}
/// <devdoc>
/// <para>Returns the index of the first occurrence of a value in a <see cref='System.Web.UI.WebControls.DataGridColumn'/>.</para>
/// </devdoc>
public int IndexOf(DataGridColumn column) {
if (column != null) {
return columns.IndexOf(column);
}
return -1;
}
/// <devdoc>
/// </devdoc>
private void OnColumnsChanged() {
if (owner != null) {
owner.OnColumnsChanged();
}
}
/// <devdoc>
/// <para>Removes a <see cref='System.Web.UI.WebControls.DataGridColumn'/> from the collection at the specified
/// index.</para>
/// </devdoc>
public void RemoveAt(int index) {
if ((index >= 0) && (index < Count)) {
columns.RemoveAt(index);
OnColumnsChanged();
}
else {
throw new ArgumentOutOfRangeException("index");
}
}
/// <devdoc>
/// <para>Removes the specified <see cref='System.Web.UI.WebControls.DataGridColumn'/> from the collection.</para>
/// </devdoc>
public void Remove(DataGridColumn column) {
int index = IndexOf(column);
if (index >= 0) {
RemoveAt(index);
}
}
/// <internalonly/>
/// <devdoc>
/// Return true if tracking state changes.
/// </devdoc>
bool IStateManager.IsTrackingViewState {
get {
return marked;
}
}
/// <internalonly/>
/// <devdoc>
/// Load previously saved state.
/// </devdoc>
void IStateManager.LoadViewState(object savedState) {
if (savedState != null) {
object[] columnsState = (object[])savedState;
if (columnsState.Length == columns.Count) {
for (int i = 0; i < columnsState.Length; i++) {
if (columnsState[i] != null) {
((IStateManager)columns[i]).LoadViewState(columnsState[i]);
}
}
}
}
}
/// <internalonly/>
/// <devdoc>
/// Start tracking state changes.
/// </devdoc>
void IStateManager.TrackViewState() {
marked = true;
int columnCount = columns.Count;
for (int i = 0; i < columnCount; i++) {
((IStateManager)columns[i]).TrackViewState();
}
}
/// <internalonly/>
/// <devdoc>
/// Return object containing state changes.
/// </devdoc>
object IStateManager.SaveViewState() {
int columnCount = columns.Count;
object[] columnsState = new object[columnCount];
bool savedState = false;
for (int i = 0; i < columnCount; i++) {
columnsState[i] = ((IStateManager)columns[i]).SaveViewState();
if (columnsState[i] != null)
savedState = true;
}
return savedState ? columnsState : null;
}
}
}
|