Redigera

Dela via


DataGridViewColumnCollection.Remove Method

Definition

Removes a column from the collection.

Overloads

Remove(String)

Removes the column with the specified name from the collection.

Remove(DataGridViewColumn)

Removes the specified column from the collection.

Remove(String)

Source:
DataGridViewColumnCollection.cs
Source:
DataGridViewColumnCollection.cs
Source:
DataGridViewColumnCollection.cs

Removes the column with the specified name from the collection.

public:
 virtual void Remove(System::String ^ columnName);
public virtual void Remove (string columnName);
abstract member Remove : string -> unit
override this.Remove : string -> unit
Public Overridable Sub Remove (columnName As String)

Parameters

columnName
String

The name of the column to delete.

Exceptions

columnName does not match the name of any column in the collection.

columnName is null.

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:

Examples

The following code example illustrates the use of this method. For more information, see How to: Remove Autogenerated Columns from a Windows Forms DataGridView Control.

private void BindDataAndInitializeColumns()
{
    dataGridView1.AutoGenerateColumns = true;
    dataGridView1.DataSource = customersDataSet;
    dataGridView1.Columns.Remove("Fax");
    dataGridView1.Columns["CustomerID"].Visible = false;
}
Private Sub BindDataAndInitializeColumns()

    With dataGridView1
        .AutoGenerateColumns = True
        .DataSource = customersDataSet
        .Columns.Remove("Fax")
        .Columns("CustomerID").Visible = False
    End With

End Sub

Remarks

The name of a column is indicated by the DataGridViewColumn.Name property.

To remove a column that is automatically generated when binding to a data source, call this method in a DataGridView.DataBindingComplete event handler.

See also

Applies to

Remove(DataGridViewColumn)

Source:
DataGridViewColumnCollection.cs
Source:
DataGridViewColumnCollection.cs
Source:
DataGridViewColumnCollection.cs

Removes the specified column from the collection.

public:
 virtual void Remove(System::Windows::Forms::DataGridViewColumn ^ dataGridViewColumn);
public virtual void Remove (System.Windows.Forms.DataGridViewColumn dataGridViewColumn);
abstract member Remove : System.Windows.Forms.DataGridViewColumn -> unit
override this.Remove : System.Windows.Forms.DataGridViewColumn -> unit
Public Overridable Sub Remove (dataGridViewColumn As DataGridViewColumn)

Parameters

dataGridViewColumn
DataGridViewColumn

The column to delete.

Exceptions

dataGridViewColumn is not in the collection.

dataGridViewColumn is null.

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:

Remarks

To remove a column that is automatically generated when binding to a data source, call this method in a DataGridView.DataBindingComplete event handler.

See also

Applies to