DataGridViewColumnCollection Class
Represents a collection of DataGridViewColumn objects in a DataGridView control.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
System.MarshalByRefObject
System.Windows.Forms.BaseCollection
System.Windows.Forms.DataGridViewColumnCollection
| Name | Description | |
|---|---|---|
![]() | DataGridViewColumnCollection(DataGridView) | Initializes a new instance of the DataGridViewColumnCollection class for the given DataGridView. |
| Name | Description | |
|---|---|---|
![]() | Count | Gets the total number of elements in the collection.(Inherited from BaseCollection.) |
![]() | DataGridView | Gets the DataGridView upon which the collection performs column-related operations. |
![]() | IsReadOnly | Gets a value indicating whether the collection is read-only.(Inherited from BaseCollection.) |
![]() | IsSynchronized | Gets a value indicating whether access to the ICollection is synchronized.(Inherited from BaseCollection.) |
![]() | Item(Int32) | Gets or sets the column at the given index in the collection. |
![]() | Item(String) | Gets or sets the column of the given name in the collection. |
![]() | List | Gets the list of elements contained in the BaseCollection instance.(Overrides BaseCollection.List.) |
![]() | SyncRoot | Gets an object that can be used to synchronize access to the BaseCollection.(Inherited from BaseCollection.) |
| Name | Description | |
|---|---|---|
![]() | Add(DataGridViewColumn) | Adds the given column to the collection. |
![]() | Add(String, String) | Adds a DataGridViewTextBoxColumn with the given column name and column header text to the collection. |
![]() | AddRange(DataGridViewColumn()) | Adds a range of columns to the collection. |
![]() | Clear() | Clears the collection. |
![]() | Contains(DataGridViewColumn) | Determines whether the collection contains the given column. |
![]() | Contains(String) | Determines whether the collection contains the column referred to by the given name. |
![]() | CopyTo(Array, Int32) | Copies all the elements of the current one-dimensional Array to the specified one-dimensional Array starting at the specified destination Array index.(Inherited from BaseCollection.) |
![]() | CopyTo(DataGridViewColumn(), Int32) | Copies the items from the collection to the given array. |
![]() | CreateObjRef(Type) | Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.) |
![]() | Equals(Object) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | GetColumnCount(DataGridViewElementStates) | Returns the number of columns that meet the given filter requirements. |
![]() | GetColumnsWidth(DataGridViewElementStates) | Returns the width, in pixels, required to display all of the columns that meet the given filter requirements. |
![]() | GetEnumerator() | Gets the object that enables iterating through the members of the collection.(Inherited from BaseCollection.) |
![]() | GetFirstColumn(DataGridViewElementStates) | Returns the first column in display order that meets the given inclusion-filter requirements. |
![]() | GetFirstColumn(DataGridViewElementStates, DataGridViewElementStates) | Returns the first column in display order that meets the given inclusion-filter and exclusion-filter requirements. |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetLastColumn(DataGridViewElementStates, DataGridViewElementStates) | Returns the last column in display order that meets the given filter requirements. |
![]() | GetLifetimeService() | Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.) |
![]() | GetNextColumn(DataGridViewColumn, DataGridViewElementStates, DataGridViewElementStates) | Gets the first column after the given column in display order that meets the given filter requirements. |
![]() | GetPreviousColumn(DataGridViewColumn, DataGridViewElementStates, DataGridViewElementStates) | Gets the last column prior to the given column in display order that meets the given filter requirements. |
![]() | GetType() | |
![]() | IndexOf(DataGridViewColumn) | Gets the index of the given DataGridViewColumn in the collection. |
![]() | InitializeLifetimeService() | Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.) |
![]() | Insert(Int32, DataGridViewColumn) | Inserts a column at the given index in the collection. |
![]() | MemberwiseClone() | |
![]() | MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.) |
![]() | OnCollectionChanged(CollectionChangeEventArgs) | Raises the CollectionChanged event. |
![]() | Remove(DataGridViewColumn) | Removes the specified column from the collection. |
![]() | Remove(String) | Removes the column with the specified name from the collection. |
![]() | RemoveAt(Int32) | Removes the column at the given index in the collection. |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() | CollectionChanged | Occurs when the collection changes. |
| Name | Description | |
|---|---|---|
![]() ![]() | ICollection.CopyTo(Array, Int32) | This API supports the product infrastructure and is not intended to be used directly from your code. Copies the entire contents of the collection to a compatible one-dimensional Array, starting at the specified index of the target array. |
![]() ![]() | IEnumerable.GetEnumerator() | This API supports the product infrastructure and is not intended to be used directly from your code. Returns an enumerator that iterates through the collection. |
![]() ![]() | IList.Add(Object) | This API supports the product infrastructure and is not intended to be used directly from your code. Adds an object to the end of the collection. |
![]() ![]() | IList.Clear() | This API supports the product infrastructure and is not intended to be used directly from your code. Removes all elements from the collection. |
![]() ![]() | IList.Contains(Object) | This API supports the product infrastructure and is not intended to be used directly from your code. Determines whether an object is in the collection. |
![]() ![]() | IList.IndexOf(Object) | This API supports the product infrastructure and is not intended to be used directly from your code. Determines the index of a specific item in the collection. |
![]() ![]() | IList.Insert(Int32, Object) | This API supports the product infrastructure and is not intended to be used directly from your code. Inserts an element into the collection at the specified index. |
![]() ![]() | IList.Remove(Object) | This API supports the product infrastructure and is not intended to be used directly from your code. Removes the first occurrence of the specified object from the collection. |
![]() ![]() | IList.RemoveAt(Int32) | This API supports the product infrastructure and is not intended to be used directly from your code. Removes the element with the specified index from the collection. |
![]() ![]() | ICollection.Count | This API supports the product infrastructure and is not intended to be used directly from your code. Gets the number of elements in the collection. |
![]() ![]() | ICollection.IsSynchronized | This API supports the product infrastructure and is not intended to be used directly from your code. Gets a value indicating whether access to the collection is synchronized. |
![]() ![]() | ICollection.SyncRoot | This API supports the product infrastructure and is not intended to be used directly from your code. Gets an object that can be used to synchronize access to the collection. |
![]() ![]() | IList.IsFixedSize | This API supports the product infrastructure and is not intended to be used directly from your code. Gets a value indicating whether the collection has a fixed size. |
![]() ![]() | IList.IsReadOnly | 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 read-only. |
![]() ![]() | IList.Item(Int32) | This API supports the product infrastructure and is not intended to be used directly from your code. Gets or sets the element at the specified index. |
| Name | Description | |
|---|---|---|
![]() | AsParallel() | Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.) |
![]() | AsQueryable() | Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.) |
![]() | Cast(Of TResult)() | Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.) |
![]() | OfType(Of TResult)() | Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.) |
You can retrieve an instance of this class through the Columns property of the DataGridView control. The collection maintains a reference to the control through the DataGridView property.
The following code example illustrates the use of this type.
Private WithEvents dataGridView1 As New DataGridView() Private Sub AddColorColumn() Dim comboBoxColumn As New DataGridViewComboBoxColumn() comboBoxColumn.Items.AddRange( _ Color.Red, Color.Yellow, Color.Green, Color.Blue) comboBoxColumn.ValueType = GetType(Color) dataGridView1.Columns.Add(comboBoxColumn) End Sub Private Sub dataGridView1_EditingControlShowing(ByVal sender As Object, _ ByVal e As DataGridViewEditingControlShowingEventArgs) _ Handles dataGridView1.EditingControlShowing Dim combo As ComboBox = CType(e.Control, ComboBox) If (combo IsNot Nothing) Then ' Remove an existing event-handler, if present, to avoid ' adding multiple handlers when the editing control is reused. RemoveHandler combo.SelectedIndexChanged, _ New EventHandler(AddressOf ComboBox_SelectedIndexChanged) ' Add the event handler. AddHandler combo.SelectedIndexChanged, _ New EventHandler(AddressOf ComboBox_SelectedIndexChanged) End If End Sub Private Sub ComboBox_SelectedIndexChanged( _ ByVal sender As Object, ByVal e As EventArgs) Dim comboBox1 As ComboBox = CType(sender, ComboBox) comboBox1.BackColor = _ CType(CType(sender, ComboBox).SelectedItem, Color) End Sub
Available since 2.0
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.







