Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / UI / WebControls / ColumnCollection.cs / 1305376 / ColumnCollection.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.WebControls {
using System;
using System.Collections;
using System.ComponentModel;
using System.Web.UI;
///
/// Represents the collection of columns to be displayed in
/// a
/// control.
///
public sealed class DataGridColumnCollection : ICollection, IStateManager {
private DataGrid owner;
private ArrayList columns;
private bool marked;
///
/// Initializes a new instance of class.
///
public DataGridColumnCollection(DataGrid owner, ArrayList columns) {
this.owner = owner;
this.columns = columns;
}
///
/// Gets the number of columns in the collection. This property is read-only.
///
[
Browsable(false)
]
public int Count {
get {
return columns.Count;
}
}
///
/// Gets a value that specifies whether items in the can be
/// modified. This property is read-only.
///
[
Browsable(false)
]
public bool IsReadOnly {
get {
return false;
}
}
///
/// Gets a value that indicates whether the is thread-safe. This property is read-only.
///
[
Browsable(false)
]
public bool IsSynchronized {
get {
return false;
}
}
///
/// Gets the object used to synchronize access to the collection. This property is read-only.
///
[
Browsable(false)
]
public Object SyncRoot {
get {
return this;
}
}
///
/// Gets a at the specified index in the
/// collection.
///
[
Browsable(false)
]
public DataGridColumn this[int index] {
get {
return (DataGridColumn)columns[index];
}
}
///
/// Appends a to the collection.
///
public void Add(DataGridColumn column) {
AddAt(-1, column);
}
///
/// Inserts a to the collection
/// at the specified index.
///
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();
}
///
/// Empties the collection of all objects.
///
public void Clear() {
columns.Clear();
OnColumnsChanged();
}
///
/// Copies the contents of the entire collection into an appending at
/// the specified index of the .
///
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++);
}
///
/// Creates an enumerator for the used to iterate through the collection.
///
public IEnumerator GetEnumerator() {
return columns.GetEnumerator();
}
///
/// Returns the index of the first occurrence of a value in a .
///
public int IndexOf(DataGridColumn column) {
if (column != null) {
return columns.IndexOf(column);
}
return -1;
}
///
///
private void OnColumnsChanged() {
if (owner != null) {
owner.OnColumnsChanged();
}
}
///
/// Removes a from the collection at the specified
/// index.
///
public void RemoveAt(int index) {
if ((index >= 0) && (index < Count)) {
columns.RemoveAt(index);
OnColumnsChanged();
}
else {
throw new ArgumentOutOfRangeException("index");
}
}
///
/// Removes the specified from the collection.
///
public void Remove(DataGridColumn column) {
int index = IndexOf(column);
if (index >= 0) {
RemoveAt(index);
}
}
///
///
/// Return true if tracking state changes.
///
bool IStateManager.IsTrackingViewState {
get {
return marked;
}
}
///
///
/// Load previously saved state.
///
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]);
}
}
}
}
}
///
///
/// Start tracking state changes.
///
void IStateManager.TrackViewState() {
marked = true;
int columnCount = columns.Count;
for (int i = 0; i < columnCount; i++) {
((IStateManager)columns[i]).TrackViewState();
}
}
///
///
/// Return object containing state changes.
///
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;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.WebControls {
using System;
using System.Collections;
using System.ComponentModel;
using System.Web.UI;
///
/// Represents the collection of columns to be displayed in
/// a
/// control.
///
public sealed class DataGridColumnCollection : ICollection, IStateManager {
private DataGrid owner;
private ArrayList columns;
private bool marked;
///
/// Initializes a new instance of class.
///
public DataGridColumnCollection(DataGrid owner, ArrayList columns) {
this.owner = owner;
this.columns = columns;
}
///
/// Gets the number of columns in the collection. This property is read-only.
///
[
Browsable(false)
]
public int Count {
get {
return columns.Count;
}
}
///
/// Gets a value that specifies whether items in the can be
/// modified. This property is read-only.
///
[
Browsable(false)
]
public bool IsReadOnly {
get {
return false;
}
}
///
/// Gets a value that indicates whether the is thread-safe. This property is read-only.
///
[
Browsable(false)
]
public bool IsSynchronized {
get {
return false;
}
}
///
/// Gets the object used to synchronize access to the collection. This property is read-only.
///
[
Browsable(false)
]
public Object SyncRoot {
get {
return this;
}
}
///
/// Gets a at the specified index in the
/// collection.
///
[
Browsable(false)
]
public DataGridColumn this[int index] {
get {
return (DataGridColumn)columns[index];
}
}
///
/// Appends a to the collection.
///
public void Add(DataGridColumn column) {
AddAt(-1, column);
}
///
/// Inserts a to the collection
/// at the specified index.
///
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();
}
///
/// Empties the collection of all objects.
///
public void Clear() {
columns.Clear();
OnColumnsChanged();
}
///
/// Copies the contents of the entire collection into an appending at
/// the specified index of the .
///
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++);
}
///
/// Creates an enumerator for the used to iterate through the collection.
///
public IEnumerator GetEnumerator() {
return columns.GetEnumerator();
}
///
/// Returns the index of the first occurrence of a value in a .
///
public int IndexOf(DataGridColumn column) {
if (column != null) {
return columns.IndexOf(column);
}
return -1;
}
///
///
private void OnColumnsChanged() {
if (owner != null) {
owner.OnColumnsChanged();
}
}
///
/// Removes a from the collection at the specified
/// index.
///
public void RemoveAt(int index) {
if ((index >= 0) && (index < Count)) {
columns.RemoveAt(index);
OnColumnsChanged();
}
else {
throw new ArgumentOutOfRangeException("index");
}
}
///
/// Removes the specified from the collection.
///
public void Remove(DataGridColumn column) {
int index = IndexOf(column);
if (index >= 0) {
RemoveAt(index);
}
}
///
///
/// Return true if tracking state changes.
///
bool IStateManager.IsTrackingViewState {
get {
return marked;
}
}
///
///
/// Load previously saved state.
///
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]);
}
}
}
}
}
///
///
/// Start tracking state changes.
///
void IStateManager.TrackViewState() {
marked = true;
int columnCount = columns.Count;
for (int i = 0; i < columnCount; i++) {
((IStateManager)columns[i]).TrackViewState();
}
}
///
///
/// Return object containing state changes.
///
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;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Transform3DGroup.cs
- StorageTypeMapping.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- InvokeAction.cs
- UnsafeNativeMethods.cs
- RangeValueProviderWrapper.cs
- SystemColorTracker.cs
- ManagementObjectCollection.cs
- DbProviderSpecificTypePropertyAttribute.cs
- SchemaDeclBase.cs
- RegexCharClass.cs
- SoapElementAttribute.cs
- DataControlLinkButton.cs
- OleDbParameter.cs
- DrawingContextDrawingContextWalker.cs
- IISMapPath.cs
- StorageEntitySetMapping.cs
- odbcmetadatafactory.cs
- XmlElementCollection.cs
- FontNameEditor.cs
- pingexception.cs
- InternalSafeNativeMethods.cs
- DetailsViewModeEventArgs.cs
- SqlBuilder.cs
- UDPClient.cs
- Vector3DAnimationUsingKeyFrames.cs
- AlternateView.cs
- HttpCacheVary.cs
- TokenFactoryCredential.cs
- GlyphInfoList.cs
- DiscoveryReferences.cs
- Transactions.cs
- DeclaredTypeValidatorAttribute.cs
- SqlIdentifier.cs
- NumericUpDownAcceleration.cs
- CheckBoxFlatAdapter.cs
- ResourceIDHelper.cs
- ExpressionEditorAttribute.cs
- ReadContentAsBinaryHelper.cs
- PathStreamGeometryContext.cs
- CommandLibraryHelper.cs
- DataControlFieldCollection.cs
- XamlWriter.cs
- FileSystemInfo.cs
- ActivationServices.cs
- ListItem.cs
- _CommandStream.cs
- StateItem.cs
- ThreadPool.cs
- XmlCharType.cs
- UIServiceHelper.cs
- HandledMouseEvent.cs
- MembershipSection.cs
- CodeDesigner.cs
- ViewUtilities.cs
- IssuedTokenParametersElement.cs
- DataRowCollection.cs
- SqlDataSourceTableQuery.cs
- DocumentGridPage.cs
- RoutingExtension.cs
- DataObjectMethodAttribute.cs
- IsolatedStorageFilePermission.cs
- COM2PropertyPageUITypeConverter.cs
- DataSourceHelper.cs
- DataGridViewRowPrePaintEventArgs.cs
- _LocalDataStore.cs
- KeyConstraint.cs
- SqlOuterApplyReducer.cs
- ProfileBuildProvider.cs
- ObjectQuery_EntitySqlExtensions.cs
- _NtlmClient.cs
- oledbconnectionstring.cs
- StoreItemCollection.cs
- COM2PropertyPageUITypeConverter.cs
- XmlAnyElementAttribute.cs
- DataServiceRequest.cs
- HttpFileCollectionWrapper.cs
- WindowsGraphicsWrapper.cs
- ApplicationInterop.cs
- Thumb.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- TrustManager.cs
- Mutex.cs
- RoleManagerEventArgs.cs
- AutomationElementIdentifiers.cs
- ThrowHelper.cs
- XpsSerializerFactory.cs
- RoleGroup.cs
- IPEndPoint.cs
- MetadataUtilsSmi.cs
- XmlSchemaElement.cs
- QueryTaskGroupState.cs
- Viewport2DVisual3D.cs
- ColumnMap.cs
- VScrollBar.cs
- ProfileGroupSettings.cs
- EnvironmentPermission.cs
- CrossAppDomainChannel.cs
- DocumentXmlWriter.cs
- SapiInterop.cs