DataGridViewColumnCollection
Namespace: Wisej.Web
Assembly: Wisej.Framework (3.5.0.0)
Represents a collection of DataGridViewColumn objects in a DataGridView control.
- C#
- VB.NET
public class DataGridViewColumnCollection : BaseCollection, IList, IList<DataGridViewColumn>, ICollection<DataGridViewColumn>, IEnumerable<DataGridViewColumn>
Public Class DataGridViewColumnCollection
Inherits BaseCollection
Implements IList, IList(Of DataGridViewColumn), ICollection(Of DataGridViewColumn), IEnumerable(Of DataGridViewColumn)
Constructors
DataGridViewColumnCollection(dataGrid)
Initializes a new instance of the DataGridViewColumnCollection class for the given DataGridView.
| Name | Type | Description |
|---|---|---|
| dataGrid | DataGridView | The DataGridView that created this collection. |
Properties
Item(index)
DataGridViewColumn: Returns the column at the given index in the collection.
Throws:
- ArgumentOutOfRangeException index is less than zero or greater than the number of columns in the collection minus one.
Item(name)
DataGridViewColumn: Returns the column of the given name in the collection.
Throws:
- ArgumentNullException name is null.
Methods
Add(column)
Adds the given DataGridViewColumn to the collection.
| Parameter | Type | Description |
|---|---|---|
| column | DataGridViewColumn | The DataGridViewColumn to add. |
Returns: Int32. The index of the column.
Throws:
- ArgumentNullException column is null.
- InvalidOperationException The associated DataGridView control is performing one of the following actions that temporarily prevents new columns from being added: - Selecting all cells in the control. - Clearing the selection.Updating column DisplayIndex property values. Or this method is being called from a handler for one of the following DataGridView events: - CellEnter - CellLeave - CellValidating - CellValidated - RowEnter - RowLeave - RowValidated - RowValidating
Add(name)
Adds a DataGridViewTextBoxColumn with the given column name to the collection.
| Parameter | Type | Description |
|---|---|---|
| name | String | The name by which the column will be referred. |
Returns: Int32. The index of the column.
Throws:
- InvalidOperationException The associated DataGridView control is performing one of the following actions that temporarily prevents new columns from being added: - Selecting all cells in the control. - Clearing the selection.Updating column DisplayIndex property values. Or this method is being called from a handler for one of the following DataGridView events: - CellEnter - CellLeave - CellValidating - CellValidated - RowEnter - RowLeave - RowValidated - RowValidating
Add(name, valueType)
Adds a DataGridViewTextBoxColumn with the given column name and call value type to the collection.
| Parameter | Type | Description |
|---|---|---|
| name | String | The name by which the column will be referred. |
| valueType | Type | The Type of the values in the cells. |
Returns: Int32. The index of the column.
Throws:
- InvalidOperationException The associated DataGridView control is performing one of the following actions that temporarily prevents new columns from being added: - Selecting all cells in the control. - Clearing the selection.Updating column DisplayIndex property values. Or this method is being called from a handler for one of the following DataGridView events: - CellEnter - CellLeave - CellValidating - CellValidated - RowEnter - RowLeave - RowValidated - RowValidating
Add(name, caption)
Adds a DataGridViewTextBoxColumn with the given column name and column header text to the collection.
| Parameter | Type | Description |
|---|---|---|
| name | String | The name by which the column will be referred. |
| caption | String | The text for the column's header. |
Returns: Int32. The index of the column.
Throws:
- InvalidOperationException The associated DataGridView control is performing one of the following actions that temporarily prevents new columns from being added: - Selecting all cells in the control. - Clearing the selection.Updating column DisplayIndex property values. Or this method is being called from a handler for one of the following DataGridView events: - CellEnter - CellLeave - CellValidating - CellValidated - RowEnter - RowLeave - RowValidated - RowValidating
Add(name, caption, valueType)
Adds a DataGridViewTextBoxColumn with the given column name, column header text, and cell value type to the collection.
| Parameter | Type | Description |
|---|---|---|
| name | String | The name by which the column will be referred. |
| caption | String | The text for the column's header. |
| valueType | Type | The Type of the values in the cells. |
Returns: Int32. The index of the column.
Throws:
- InvalidOperationException The associated DataGridView control is performing one of the following actions that temporarily prevents new columns from being added: - Selecting all cells in the control. - Clearing the selection.Updating column DisplayIndex property values. Or this method is being called from a handler for one of the following DataGridView events: - CellEnter - CellLeave - CellValidating - CellValidated - RowEnter - RowLeave - RowValidated - RowValidating
AddRange(newColumns)
Adds a range of columns to the collection.
| Parameter | Type | Description |
|---|---|---|
| newColumns | DataGridViewColumn[] | An array of DataGridViewColumn objects to add. |
Throws:
- ArgumentNullException newColumns is null.
- InvalidOperationException The associated DataGridView control is performing one of the following actions that temporarily prevents new columns from being added: - Selecting all cells in the control. - Clearing the selection.Updating column DisplayIndex property values. Or this method is being called from a handler for one of the following DataGridView events: - CellEnter - CellLeave - CellValidating - CellValidated - RowEnter - RowLeave - RowValidated - RowValidating
Clear()
Clears the collection.
Throws:
- InvalidOperationException The associated DataGridView control is performing one of the following actions that temporarily prevents new columns from being added: - Selecting all cells in the control. - Clearing the selection.Updating column DisplayIndex property values. Or this method is being called from a handler for one of the following DataGridView events: - CellEnter - CellLeave - CellValidating - CellValidated - RowEnter - RowLeave - RowValidated - RowValidating
Clear(dispose)
Clears the collection and disposes the columns.
| Parameter | Type | Description |
|---|---|---|
| dispose | Boolean |
Contains(column)
Determines whether the collection contains the given DataGridViewColumn.
| Parameter | Type | Description |
|---|---|---|
| column | DataGridViewColumn | The DataGridViewColumn to look for. |
Returns: Boolean. true if the given column is in the collection; otherwise, false.
Contains(name)
Determines whether the collection contains the given DataGridViewColumn.
| Parameter | Type | Description |
|---|---|---|
| name | String | The name of the column to look for. |
Returns: Boolean. true if the given column is in the collection; otherwise, false.
CopyTo(array, index)
Copies the items from the collection to the given array.
| Parameter | Type | Description |
|---|---|---|
| array | DataGridViewColumn[] | The destination DataGridViewColumn array. |
| index | Int32 | The index of the destination array at which to start copying. |
GetColumnCount(includeFilter)
Returns the number of columns that match the includeFilter .
| Parameter | Type | Description |
|---|---|---|
| includeFilter | DataGridViewElementStates | A combination of the DataGridViewElementStates values for inclusion. |
Returns: Int32. The number of columns that match the filter.
Throws:
- ArgumentException includeFilter is not a valid combination of DataGridViewElementStates values.
GetColumnsWidth(includeFilter)
Returns the width, in pixels, required to display all of the columns that meet the includeFilter .
| Parameter | Type | Description |
|---|---|---|
| includeFilter | DataGridViewElementStates | A combination of the DataGridViewElementStates values for inclusion. |
Returns: Int32. The width, in pixels, that is necessary to display all of the columns that match the filter.
Throws:
- ArgumentException includeFilter is not a valid combination of DataGridViewElementStates values.
GetFirstColumn(includeFilter, excludeFilter)
Returns the first DataGridViewColumn in display order that matches the includeFilter and excludeFilter .
| Parameter | Type | Description |
|---|---|---|
| includeFilter | DataGridViewElementStates | A combination of the DataGridViewElementStates values for inclusion. |
| excludeFilter | DataGridViewElementStates | A combination of the DataGridViewElementStates values for exclusion. |
Returns: DataGridViewColumn. The first DataGridViewColumn in display order that matches the given filters, or null if no column is found.
Throws:
- ArgumentException At least one of the filter values is not a valid combination of DataGridViewElementStates values.
GetLastColumn(includeFilter, excludeFilter)
Returns the last DataGridViewColumn in display order that matches the includeFilter and excludeFilter .
| Parameter | Type | Description |
|---|---|---|
| includeFilter | DataGridViewElementStates | A combination of the DataGridViewElementStates values for inclusion. |
| excludeFilter | DataGridViewElementStates | A combination of the DataGridViewElementStates values for exclusion. |
Returns: DataGridViewColumn. The last displayed DataGridViewColumn in display order that matches the specified filters, or null if no column is found.
Throws:
- ArgumentException At least one of the filter values is not a valid combination of DataGridViewElementStates values.
GetNextColumn(startColumn, includeFilter, excludeFilter)
Returns the first DataGridViewColumn after the given column in display order that matches the includeFilter and excludeFilter .
| Parameter | Type | Description |
|---|---|---|
| startColumn | DataGridViewColumn | The column from which to start searching for the next column. |
| includeFilter | DataGridViewElementStates | A combination of the DataGridViewElementStates values for inclusion. |
| excludeFilter | DataGridViewElementStates | A combination of the DataGridViewElementStates values for exclusion. |
Returns: DataGridViewColumn. The next DataGridViewColumn that matches the filters, or null if no column is found.
Throws:
- ArgumentNullException startColumn is null.
- ArgumentException At least one of the filter values is not a valid combination of DataGridViewElementStates values.
GetPreviousColumn(startColumn, includeFilter, excludeFilter)
Returns the last DataGridViewColumn prior to the given column in display order that matches the includeFilter and excludeFilter .
| Parameter | Type | Description |
|---|---|---|
| startColumn | DataGridViewColumn | The column from which to start searching for the previous column. |
| includeFilter | DataGridViewElementStates | A combination of the DataGridViewElementStates values for inclusion. |
| excludeFilter | DataGridViewElementStates | A combination of the DataGridViewElementStates values for exclusion. |
Returns: DataGridViewColumn. The previous column that matches the given filters, or null if no column is found.
Throws:
- ArgumentNullException startColumn is null.
- ArgumentException At least one of the filter values is not a valid combination of DataGridViewElementStates values.
IndexOf(column)
Returns the index of the given DataGridViewColumn in the collection.
| Parameter | Type | Description |
|---|---|---|
| column | DataGridViewColumn | The DataGridViewColumn to return the index of. |
Returns: Int32. The index of the given DataGridViewColumn.
IndexOf(name)
Returns the index of the DataGridViewColumn with the specified name from the collection.
| Parameter | Type | Description |
|---|---|---|
| name | String | The name of the column to find. |
Returns: Int32. The index of the given DataGridViewColumn.
Throws:
- ArgumentNullException name is null.
Insert(index, column)
Inserts a DataGridViewColumn at the given index in the collection.
| Parameter | Type | Description |
|---|---|---|
| index | Int32 | The zero-based index at which to insert the given column. |
| column | DataGridViewColumn | The DataGridViewColumn to insert. |
Throws:
- ArgumentNullException column is null.
- InvalidOperationException The associated DataGridView control is performing one of the following actions that temporarily prevents new columns from being added:
- Selecting all cells in the control
- Clearing the selection
- Updating a column's DisplayIndex property value or this method is being called from a handler for one of the following DataGridView events:
- CellEnter
- CellLeave
- CellValidating
- CellValidated
- RowEnter
- RowLeave
- RowValidated
- RowValidating or column already belongs to a DataGridView control; or the column 's SortMode property value is Automatic and the SelectionMode property value is FullColumnSelect or ColumnHeaderSelect. Use the control's BeginInit and EndInit methods to temporarily set conflicting property values; or the column 's InheritedAutoSizeMode property value is ColumnHeader and the ColumnHeadersVisible property value is false; or column has an InheritedAutoSizeMode property value of Fill and a Frozen property value of true; or column has DisplayIndex and Frozen property values that would display it among a set of adjacent columns with the opposite Frozen property value; or the DataGridView control contains at least one row and column has a CellType property value of null.
Remove(column)
Removes the specified DataGridViewColumn from the collection.
| Parameter | Type | Description |
|---|---|---|
| column | DataGridViewColumn | The column to delete. |
Throws:
- ArgumentException column is not in the collection.
- ArgumentNullException column is null.
- InvalidOperationException The associated DataGridView control is performing one of the following actions that temporarily prevents new columns from being added:
- Selecting all cells in the control
- Clearing the selection
- Updating a column's DisplayIndex property value or this method is being called from a handler for one of the following DataGridView events:
- CellEnter
- CellLeave
- CellValidating
- CellValidated
- RowEnter
- RowLeave
- RowValidated
- RowValidating
Remove(name)
Removes the DataGridViewColumn with the specified name from the collection.
| Parameter | Type | Description |
|---|---|---|
| name | String | The name of the column to delete. |
Throws:
- ArgumentException name does not match the name of any column in the collection.
- ArgumentNullException name is null.
- InvalidOperationException The associated DataGridView control is performing one of the following actions that temporarily prevents new columns from being added:
- Selecting all cells in the control
- Clearing the selection
- Updating a column's DisplayIndex property value or this method is being called from a handler for one of the following DataGridView events:
- CellEnter
- CellLeave
- CellValidating
- CellValidated
- RowEnter
- RowLeave
- RowValidated
- RowValidating
RemoveAt(index)
Removes the DataGridViewColumn at the given index in the collection.
| Parameter | Type | Description |
|---|---|---|
| index | Int32 | The index of the column to delete. |
Throws:
- ArgumentOutOfRangeException index is less than zero or greater than the number of columns in the control minus one.
- InvalidOperationException The associated DataGridView control is performing one of the following actions that temporarily prevents new columns from being added:
- Selecting all cells in the control
- Clearing the selection
- Updating a column's DisplayIndex property value or this method is being called from a handler for one of the following DataGridView events:
- CellEnter
- CellLeave
- CellValidating
- CellValidated
- RowEnter
- RowLeave
- RowValidated
- RowValidating
SetColumnIndex(column, newIndex)
Moves the specified column to the new newIndex .
| Parameter | Type | Description |
|---|---|---|
| column | DataGridViewColumn | Column to move to the new newIndex . |
| newIndex | Int32 | New index and display index of the column . |
This method updates both the column's index in the column collection and the display index without firing the ColumnDisplayIndexChanged event.
Events
CollectionChanged
CollectionChangeEventHandler Fired when the collection changes.