DataGridColumnCollection Class

 

A collection of DataGridColumn-derived column objects that represent the columns in a DataGrid control. This class cannot be inherited.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

System::Object
  System.Web.UI.WebControls::DataGridColumnCollection

public ref class DataGridColumnCollection sealed : ICollection, 
	IEnumerable, IStateManager

NameDescription
System_CAPS_pubmethodDataGridColumnCollection(DataGrid^, ArrayList^)

Initializes a new instance of the DataGridColumnCollection class.

NameDescription
System_CAPS_pubpropertyCount

Gets the number of columns in the DataGridColumnCollection collection.

System_CAPS_pubpropertyIsReadOnly

Gets a value that indicates whether the columns in the DataGridColumnCollection collection can be modified.

System_CAPS_pubpropertyIsSynchronized

Gets a value indicating whether access to the DataGridColumnCollection collection is synchronized (thread safe).

System_CAPS_pubpropertyItem[Int32]

Gets a DataGridColumn-derived column object from the DataGridColumnCollection collection at the specified index.

System_CAPS_pubpropertySyncRoot

Gets the object that can be used to synchronize access to the DataGridColumnCollection collection.

NameDescription
System_CAPS_pubmethodAdd(DataGridColumn^)

Appends the specified DataGridColumn-derived column object to the end of the DataGridColumnCollection collection.

System_CAPS_pubmethodAddAt(Int32, DataGridColumn^)

Inserts a DataGridColumn-derived column object in the DataGridColumnCollection collection at the specified index.

System_CAPS_pubmethodClear()

Removes all DataGridColumn-derived column objects from the DataGridColumnCollection collection.

System_CAPS_pubmethodCopyTo(Array^, Int32)

Copies the items from the DataGridColumnCollection collection to the specified System::Array, starting at the specified index in the System::Array.

System_CAPS_pubmethodEquals(Object^)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodGetEnumerator()

Returns a System.Collections::IEnumerator interface that contains all the DataGridColumn-derived column objects in the DataGridColumnCollection collection.

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodIndexOf(DataGridColumn^)

Returns the index of the specified DataGridColumn-derived column object from the DataGridColumnCollection collection.

System_CAPS_pubmethodRemove(DataGridColumn^)

Removes the specified DataGridColumn-derived column object from the DataGridColumnCollection collection.

System_CAPS_pubmethodRemoveAt(Int32)

Removes a DataGridColumn-derived column object from the DataGridColumnCollection collection at the specified index.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodIStateManager::LoadViewState(Object^)

This API supports the product infrastructure and is not intended to be used directly from your code. Loads the previously saved state.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIStateManager::SaveViewState()

This API supports the product infrastructure and is not intended to be used directly from your code. Returns an object containing state changes.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIStateManager::TrackViewState()

This API supports the product infrastructure and is not intended to be used directly from your code. Starts tracking state changes.

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIStateManager::IsTrackingViewState

This API supports the product infrastructure and is not intended to be used directly from your code. Gets a value indicating whether the collection is tracking its view-state changes.

NameDescription
System_CAPS_pubmethodAsParallel()

Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)

System_CAPS_pubmethodAsQueryable()

Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.)

System_CAPS_pubmethodCast<TResult>()

Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.)

System_CAPS_pubmethodOfType<TResult>()

Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.)

Use the DataGridColumnCollection collection to programmatically manage a collection of DataGridColumn-derived column objects. These objects represent the columns in a DataGrid control. You can add, remove, or insert columns in the DataGridColumnCollection collection.

System_CAPS_noteNote

When the AutoGenerateColumns property is set to true, the columns created by the DataGrid control are not added to the Columns collection.

The DataGrid control does not store the contents of its Columns collection in the view state. To add or remove a column dynamically, you must programmatically add or remove the column every time the page is refreshed. Provide a Page_Init function that adds or removes the column before the DataGrid control's state is reloaded and the control is rebuilt. Otherwise, the changes to the Columns collection are not reflected in the DataGrid control when it is displayed.

System_CAPS_noteNote

Although you can programmatically add columns to or remove columns from the Columns collection of the DataGrid control, it is easier to list the columns statically and then use the Visible property to display or hide each column.

The order of the columns in the collection determines the order that the columns are displayed in the DataGrid control.

The following table lists the different column classes that derive from the DataGridColumn class.

Column Class

Description

BoundColumn

A column that is bound to a field in a data source. It displays each item in the field as text. This is the default column type for the DataGrid control.

ButtonColumn

A column that displays a command button for each item in the column. This allows you to create a column of custom button controls, such as Add or Remove buttons.

EditCommandColumn

A column that contains editing commands for each item in the column.

HyperLinkColumn

A column that displays each item in the column as a hyperlink. The contents of the column can be bound to a field in a data source, or to static text.

TemplateColumn

A column that displays each item in the column according to a specified template. This allows you to control the content of the column, for example to display images.

System_CAPS_noteNote

The DataGridColumn class is the base class for the column classes listed. It is not used directly in the DataGridColumnCollection collection.

The following code example demonstrates how to use the DataGridColumnCollection collection to dynamically add a column to the DataGrid control. Note that the Columns property of the DataGrid control is an instance of the DataGridColumnCollection class.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: