DataGridViewColumnCollection Class
TOC
Collapse the table of content
Expand the table of content

DataGridViewColumnCollection Class

 

Represents a collection of DataGridViewColumn objects in a DataGridView control.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

System.Object
  System.MarshalByRefObject
    System.Windows.Forms.BaseCollection
      System.Windows.Forms.DataGridViewColumnCollection

[ListBindableAttribute(false)]
public class DataGridViewColumnCollection : BaseCollection, IList, 
	ICollection, IEnumerable

NameDescription
System_CAPS_pubmethodDataGridViewColumnCollection(DataGridView)

Initializes a new instance of the DataGridViewColumnCollection class for the given DataGridView.

NameDescription
System_CAPS_pubpropertyCount

Gets the total number of elements in the collection.(Inherited from BaseCollection.)

System_CAPS_protpropertyDataGridView

Gets the DataGridView upon which the collection performs column-related operations.

System_CAPS_pubpropertyIsReadOnly

Gets a value indicating whether the collection is read-only.(Inherited from BaseCollection.)

System_CAPS_pubpropertyIsSynchronized

Gets a value indicating whether access to the ICollection is synchronized.(Inherited from BaseCollection.)

System_CAPS_pubpropertyItem[Int32]

Gets or sets the column at the given index in the collection.

System_CAPS_pubpropertyItem[String]

Gets or sets the column of the given name in the collection.

System_CAPS_protpropertyList

Gets the list of elements contained in the BaseCollection instance.(Overrides BaseCollection.List.)

System_CAPS_pubpropertySyncRoot

Gets an object that can be used to synchronize access to the BaseCollection.(Inherited from BaseCollection.)

NameDescription
System_CAPS_pubmethodAdd(DataGridViewColumn)

Adds the given column to the collection.

System_CAPS_pubmethodAdd(String, String)

Adds a DataGridViewTextBoxColumn with the given column name and column header text to the collection.

System_CAPS_pubmethodAddRange(DataGridViewColumn[])

Adds a range of columns to the collection.

System_CAPS_pubmethodClear()

Clears the collection.

System_CAPS_pubmethodContains(DataGridViewColumn)

Determines whether the collection contains the given column.

System_CAPS_pubmethodContains(String)

Determines whether the collection contains the column referred to by the given name.

System_CAPS_pubmethodCopyTo(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.)

System_CAPS_pubmethodCopyTo(DataGridViewColumn[], Int32)

Copies the items from the collection to the given array.

System_CAPS_pubmethodCreateObjRef(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.)

System_CAPS_pubmethodEquals(Object)

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

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetColumnCount(DataGridViewElementStates)

Returns the number of columns that meet the given filter requirements.

System_CAPS_pubmethodGetColumnsWidth(DataGridViewElementStates)

Returns the width, in pixels, required to display all of the columns that meet the given filter requirements.

System_CAPS_pubmethodGetEnumerator()

Gets the object that enables iterating through the members of the collection.(Inherited from BaseCollection.)

System_CAPS_pubmethodGetFirstColumn(DataGridViewElementStates)

Returns the first column in display order that meets the given inclusion-filter requirements.

System_CAPS_pubmethodGetFirstColumn(DataGridViewElementStates, DataGridViewElementStates)

Returns the first column in display order that meets the given inclusion-filter and exclusion-filter requirements.

System_CAPS_pubmethodGetHashCode()

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

System_CAPS_pubmethodGetLastColumn(DataGridViewElementStates, DataGridViewElementStates)

Returns the last column in display order that meets the given filter requirements.

System_CAPS_pubmethodGetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodGetNextColumn(DataGridViewColumn, DataGridViewElementStates, DataGridViewElementStates)

Gets the first column after the given column in display order that meets the given filter requirements.

System_CAPS_pubmethodGetPreviousColumn(DataGridViewColumn, DataGridViewElementStates, DataGridViewElementStates)

Gets the last column prior to the given column in display order that meets the given filter requirements.

System_CAPS_pubmethodGetType()

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

System_CAPS_pubmethodIndexOf(DataGridViewColumn)

Gets the index of the given DataGridViewColumn in the collection.

System_CAPS_pubmethodInitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodInsert(Int32, DataGridViewColumn)

Inserts a column at the given index in the collection.

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.)

System_CAPS_protmethodOnCollectionChanged(CollectionChangeEventArgs)

Raises the CollectionChanged event.

System_CAPS_pubmethodRemove(DataGridViewColumn)

Removes the specified column from the collection.

System_CAPS_pubmethodRemove(String)

Removes the column with the specified name from the collection.

System_CAPS_pubmethodRemoveAt(Int32)

Removes the column at the given index in the collection.

System_CAPS_pubmethodToString()

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

NameDescription
System_CAPS_pubeventCollectionChanged

Occurs when the collection changes.

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodICollection.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.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIEnumerable.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.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIList.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.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIList.Clear()

This API supports the product infrastructure and is not intended to be used directly from your code. Removes all elements from the collection.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIList.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.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIList.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.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIList.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.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIList.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.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIList.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.

System_CAPS_pubinterfaceSystem_CAPS_privpropertyICollection.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.

System_CAPS_pubinterfaceSystem_CAPS_privpropertyICollection.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.

System_CAPS_pubinterfaceSystem_CAPS_privpropertyICollection.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.

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIList.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.

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIList.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.

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIList.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.

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.)

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 DataGridView dataGridView1 = new DataGridView();

private void AddColorColumn()
{
    DataGridViewComboBoxColumn comboBoxColumn =
        new DataGridViewComboBoxColumn();
    comboBoxColumn.Items.AddRange(
        Color.Red, Color.Yellow, Color.Green, Color.Blue);
    comboBoxColumn.ValueType = typeof(Color);
    dataGridView1.Columns.Add(comboBoxColumn);
    dataGridView1.EditingControlShowing +=
        new DataGridViewEditingControlShowingEventHandler(
        dataGridView1_EditingControlShowing);
}

private void dataGridView1_EditingControlShowing(object sender,
    DataGridViewEditingControlShowingEventArgs e)
{
    ComboBox combo = e.Control as ComboBox;
    if (combo != null)
    {
        // Remove an existing event-handler, if present, to avoid 
        // adding multiple handlers when the editing control is reused.
        combo.SelectedIndexChanged -=
            new EventHandler(ComboBox_SelectedIndexChanged);

        // Add the event handler. 
        combo.SelectedIndexChanged +=
            new EventHandler(ComboBox_SelectedIndexChanged);
    }
}

private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    ((ComboBox)sender).BackColor = (Color)((ComboBox)sender).SelectedItem;
}

.NET Framework
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.

Return to top
Show:
© 2016 Microsoft