DataGridViewColumnCollection.Remove 方法

定義

從集合中移除資料行。Removes a column from the collection.

多載

Remove(String)

從集合移除具有指定名稱的資料行。Removes the column with the specified name from the collection.

Remove(DataGridViewColumn)

從集合中移除指定的資料行。Removes the specified column from the collection.

Remove(String)

從集合移除具有指定名稱的資料行。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)

參數

columnName
String

要刪除的資料行名稱。The name of the column to delete.

例外狀況

columnName 不符合集合中任何資料行的名稱。columnName does not match the name of any column in the collection.

columnNamenullcolumnName is null.

相關聯的 DataGridView 控制項正在執行下列其中一個動作,暫時阻止加入新的資料行: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.

- 更新資料行 DisplayIndex 屬性值。- Updating column DisplayIndex property values.

-或--or- 這個方法正從下列其中一個 DataGridView 事件的處理常式進行呼叫:This method is being called from a handler for one of the following DataGridView events:

範例

下列程式碼範例說明如何使用這個方法。The following code example illustrates the use of this method. 如需詳細資訊,請參閱如何:從 Windows Forms DataGridView 控制項中移除自動產生的資料行。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

備註

資料行的名稱是由DataGridViewColumn.Name屬性所表示。The name of a column is indicated by the DataGridViewColumn.Name property.

若要移除系結至資料來源時自動產生的資料行, 請在DataGridView.DataBindingComplete事件處理常式中呼叫這個方法。To remove a column that is automatically generated when binding to a data source, call this method in a DataGridView.DataBindingComplete event handler.

另請參閱

Remove(DataGridViewColumn)

從集合中移除指定的資料行。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

參數

dataGridViewColumn
DataGridViewColumn

要刪除的資料行。The column to delete.

例外狀況

dataGridViewColumn 不在集合中。dataGridViewColumn is not in the collection.

dataGridViewColumnnulldataGridViewColumn is null.

相關聯的 DataGridView 控制項正在執行下列其中一個動作,暫時阻止加入新的資料行: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.

- 更新資料行 DisplayIndex 屬性值。- Updating column DisplayIndex property values.

-或--or- 這個方法正從下列其中一個 DataGridView 事件的處理常式進行呼叫:This method is being called from a handler for one of the following DataGridView events:

備註

若要移除系結至資料來源時自動產生的資料行, 請在DataGridView.DataBindingComplete事件處理常式中呼叫這個方法。To remove a column that is automatically generated when binding to a data source, call this method in a DataGridView.DataBindingComplete event handler.

另請參閱

適用於