DataGridViewCheckBoxColumn 類別

定義

裝載 DataGridViewCheckBoxCell 物件的集合。Hosts a collection of DataGridViewCheckBoxCell objects.

public ref class DataGridViewCheckBoxColumn : System::Windows::Forms::DataGridViewColumn
[System.Drawing.ToolboxBitmap(typeof(System.Windows.Forms.DataGridViewCheckBoxColumn), "DataGridViewCheckBoxColumn")]
public class DataGridViewCheckBoxColumn : System.Windows.Forms.DataGridViewColumn
[System.Drawing.ToolboxBitmap(typeof(System.Windows.Forms.DataGridViewCheckBoxColumn), "DataGridViewCheckBoxColumn.bmp")]
public class DataGridViewCheckBoxColumn : System.Windows.Forms.DataGridViewColumn
[<System.Drawing.ToolboxBitmap(typeof(System.Windows.Forms.DataGridViewCheckBoxColumn), "DataGridViewCheckBoxColumn")>]
type DataGridViewCheckBoxColumn = class
    inherit DataGridViewColumn
[<System.Drawing.ToolboxBitmap(typeof(System.Windows.Forms.DataGridViewCheckBoxColumn), "DataGridViewCheckBoxColumn.bmp")>]
type DataGridViewCheckBoxColumn = class
    inherit DataGridViewColumn
Public Class DataGridViewCheckBoxColumn
Inherits DataGridViewColumn
繼承
屬性

範例

下列程式碼範例示範如何使用 DataGridViewCheckBoxColumn 來標示哪些員工不在辦公室。The following code example demonstrates how to use a DataGridViewCheckBoxColumn to mark which employees are out of the office. 此範例是類別總覽主題中可用之較大範例的一部分 DataGridViewComboBoxColumnThis example is part of a larger example available in the DataGridViewComboBoxColumn class overview topic.

private:
    void AddOutOfOfficeColumn()
    {
        DataGridViewCheckBoxColumn^ column = gcnew DataGridViewCheckBoxColumn();
        {
            column->HeaderText = ColumnName::OutOfOffice.ToString();
            column->Name = ColumnName::OutOfOffice.ToString();
            column->AutoSizeMode = 
                DataGridViewAutoSizeColumnMode::DisplayedCells;
            column->FlatStyle = FlatStyle::Standard;
            column->ThreeState = true;
            column->CellTemplate = gcnew DataGridViewCheckBoxCell();
            column->CellTemplate->Style->BackColor = Color::Beige;
        }

        DataGridView1->Columns->Insert(0, column);
    }
private void AddOutOfOfficeColumn()
{
    DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
    {
        column.HeaderText = ColumnName.OutOfOffice.ToString();
        column.Name = ColumnName.OutOfOffice.ToString();
        column.AutoSizeMode = 
            DataGridViewAutoSizeColumnMode.DisplayedCells;
        column.FlatStyle = FlatStyle.Standard;
        column.ThreeState = true;
        column.CellTemplate = new DataGridViewCheckBoxCell();
        column.CellTemplate.Style.BackColor = Color.Beige;
    }

    DataGridView1.Columns.Insert(0, column);
}
Private Sub AddOutOfOfficeColumn()
    Dim column As New DataGridViewCheckBoxColumn()
    With column
        .HeaderText = ColumnName.OutOfOffice.ToString()
        .Name = ColumnName.OutOfOffice.ToString()
        .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
        .FlatStyle = FlatStyle.Standard
        .CellTemplate = New DataGridViewCheckBoxCell()
        .CellTemplate.Style.BackColor = Color.Beige
    End With

    DataGridView1.Columns.Insert(0, column)
End Sub

備註

DataGridViewCheckBoxColumn類別是類別的特製化型別, DataGridViewColumn 用來以邏輯方式裝載表示二進位狀態的資料格。The DataGridViewCheckBoxColumn class is a specialized type of the DataGridViewColumn class used to logically host cells that indicate binary state. DataGridViewCheckBoxColumn DataGridViewCheckBoxCell 在相交它的每一個中都有相關聯的 DataGridViewRowA DataGridViewCheckBoxColumn has an associated DataGridViewCheckBoxCell in every DataGridViewRow that intersects it. 每個資料格都會提供類似于控制項的使用者介面 (UI) CheckBoxEach cell supplies a user interface (UI) that is similar to a CheckBox control.

此資料行類型的預設排序模式為 NotSortableThe default sort mode for this column type is NotSortable.

一般而言,核取方塊資料格的值適用于儲存體、任何其他資料,或執行大量作業。Typically, check box cell values are intended either for storage, like any other data, or for performing bulk operations. 如果您想要在使用者按一下核取方塊資料格時立即回應,您可以處理 DataGridView.CellContentClick 事件,但此事件會在資料格值更新之前發生。If you want to respond immediately when users click a check box cell, you can handle the DataGridView.CellContentClick event, but this event occurs before the cell value is updated. 如果您在按一下時需要新的值,有一個選項是根據目前的值來計算預期值的值。If you need the new value at the time of the click, one option is to calculate what the expected value will be based on the current value. 另一種方法是立即認可變更,並處理 DataGridView.CellValueChanged 事件以回應它。Another approach is to commit the change immediately, and handle the DataGridView.CellValueChanged event to respond to it. 若要在按一下資料格時認可變更,您必須處理 DataGridView.CurrentCellDirtyStateChanged 事件。To commit the change when the cell is clicked, you must handle the DataGridView.CurrentCellDirtyStateChanged event. 在處理常式中,如果目前的儲存格是核取方塊資料格,請呼叫 DataGridView.CommitEdit 方法並傳入 Commit 值。In the handler, if the current cell is a check box cell, call the DataGridView.CommitEdit method and pass in the Commit value.

給繼承者的注意事項

當您從衍生 DataGridViewCheckBoxColumn 類別,並將新的屬性加入至衍生類別時,請務必覆寫 Clone() 方法,以便在複製作業期間複製新的屬性。When you derive from DataGridViewCheckBoxColumn and add new properties to the derived class, be sure to override the Clone() method to copy the new properties during cloning operations. 您也應該呼叫基類的方法, Clone() 以便將基類的屬性複製到新的資料格。You should also call the base class's Clone() method so that the properties of the base class are copied to the new cell.

建構函式

DataGridViewCheckBoxColumn()

初始化 DataGridViewCheckBoxColumn 類別的新執行個體為預設狀態。Initializes a new instance of the DataGridViewCheckBoxColumn class to the default state.

DataGridViewCheckBoxColumn(Boolean)

初始化 DataGridViewCheckBoxColumn 的新執行個體,並設定其顯示具有兩種或三種狀態的核取方塊。Initializes a new instance of the DataGridViewCheckBoxColumn and configures it to display check boxes with two or three states.

屬性

AutoSizeMode

取得或設定資料行自動調整其寬度所根據的模式。Gets or sets the mode by which the column automatically adjusts its width.

(繼承來源 DataGridViewColumn)
CellTemplate

取得或設定用來建立新儲存格的樣板。Gets or sets the template used to create new cells.

CellType

取得儲存格樣板的執行階段類型。Gets the run-time type of the cell template.

(繼承來源 DataGridViewColumn)
ContextMenuStrip

取得或設定資料行的捷徑功能表。Gets or sets the shortcut menu for the column.

(繼承來源 DataGridViewColumn)
DataGridView

取得與這個項目有關聯的 DataGridView 控制項。Gets the DataGridView control associated with this element.

(繼承來源 DataGridViewElement)
DataPropertyName

取得或設定 DataGridViewColumn 所繫結的資料來源屬性或資料庫資料行的名稱。Gets or sets the name of the data source property or database column to which the DataGridViewColumn is bound.

(繼承來源 DataGridViewColumn)
DefaultCellStyle

取得或設定資料行的預設儲存格樣式。Gets or sets the column's default cell style.

DefaultHeaderCellType

取得或設定預設標題儲存格的執行階段型別。Gets or sets the run-time type of the default header cell.

(繼承來源 DataGridViewBand)
Displayed

取得值,指出此群組列目前是否顯示在螢幕上。Gets a value indicating whether the band is currently displayed onscreen.

(繼承來源 DataGridViewBand)
DisplayIndex

取得或設定相對於目前所顯示之資料行的資料行顯示順序。Gets or sets the display order of the column relative to the currently displayed columns.

(繼承來源 DataGridViewColumn)
DividerWidth

取得或設定資料行分割線的寬度 (以像素為單位)。Gets or sets the width, in pixels, of the column divider.

(繼承來源 DataGridViewColumn)
FalseValue

取得或設定基礎值,其對應到以未核取的方塊形式出現的 false 儲存格值。Gets or sets the underlying value corresponding to a cell value of false, which appears as an unchecked box.

FillWeight

取得或設定值,表示處於填入模式中的資料行寬度,相對於控制項中處於填入模式的資料行寬度。Gets or sets a value that represents the width of the column when it is in fill mode relative to the widths of other fill-mode columns in the control.

(繼承來源 DataGridViewColumn)
FlatStyle

取得或設定核取方塊儲存格的平面樣式外觀。Gets or sets the flat style appearance of the check box cells.

Frozen

取得或設定值,指出當使用者水平捲動 DataGridView 控制項時,資料行是否會跟著移動。Gets or sets a value indicating whether a column will move when a user scrolls the DataGridView control horizontally.

(繼承來源 DataGridViewColumn)
HasDefaultCellStyle

取得指出是否已經設定 DefaultCellStyle 屬性的值。Gets a value indicating whether the DefaultCellStyle property has been set.

(繼承來源 DataGridViewBand)
HeaderCell

取得或設定表示資料行行首的 DataGridViewColumnHeaderCellGets or sets the DataGridViewColumnHeaderCell that represents the column header.

(繼承來源 DataGridViewColumn)
HeaderCellCore

取得或設定 DataGridViewBand 的標題儲存格。Gets or sets the header cell of the DataGridViewBand.

(繼承來源 DataGridViewBand)
HeaderText

取得或設定資料行行首儲存格上的標題文字。Gets or sets the caption text on the column's header cell.

(繼承來源 DataGridViewColumn)
IndeterminateValue

取得或設定基礎值,其對應到以停用的核取方塊形式出現的不定或 null 儲存格值。Gets or sets the underlying value corresponding to an indeterminate or null cell value, which appears as a disabled checkbox.

Index

取得 DataGridView 控制項內群組列的相對位置。Gets the relative position of the band within the DataGridView control.

(繼承來源 DataGridViewBand)
InheritedAutoSizeMode

取得資料行的作用中調整大小模式。Gets the sizing mode in effect for the column.

(繼承來源 DataGridViewColumn)
InheritedStyle

取得目前套用至資料行的儲存格樣式。Gets the cell style currently applied to the column.

(繼承來源 DataGridViewColumn)
IsDataBound

取得值指出資料行是否繫結至資料來源。Gets a value indicating whether the column is bound to a data source.

(繼承來源 DataGridViewColumn)
IsRow

取得值,指出群組列是否表示資料列。Gets a value indicating whether the band represents a row.

(繼承來源 DataGridViewBand)
MinimumWidth

取得或設定資料行的最小寬度 (以像素為單位)。Gets or sets the minimum width, in pixels, of the column.

(繼承來源 DataGridViewColumn)
Name

取得或設定資料行的名稱。Gets or sets the name of the column.

(繼承來源 DataGridViewColumn)
ReadOnly

取得或設定值,指出使用者是否可以編輯資料行的儲存格。Gets or sets a value indicating whether the user can edit the column's cells.

(繼承來源 DataGridViewColumn)
Resizable

取得或設定值,指出資料行是否可以重新調整大小。Gets or sets a value indicating whether the column is resizable.

(繼承來源 DataGridViewColumn)
Selected

取得或設定值,指出群組列是否位於已選取的使用者介面 (UI) 狀態下。Gets or sets a value indicating whether the band is in a selected user interface (UI) state.

(繼承來源 DataGridViewBand)
Site

取得或設定資料行的站台。Gets or sets the site of the column.

(繼承來源 DataGridViewColumn)
SortMode

取得或設定資料行的排序模式。Gets or sets the sort mode for the column.

(繼承來源 DataGridViewColumn)
State

取得此項目的使用者介面 (UI) 狀態。Gets the user interface (UI) state of the element.

(繼承來源 DataGridViewElement)
Tag

取得或設定物件,其中包含與群組列相關的資料。Gets or sets the object that contains data to associate with the band.

(繼承來源 DataGridViewBand)
ThreeState

取得或設定值,指出裝載的核取方塊儲存格是否允許三種而非兩種核取狀態。Gets or sets a value indicating whether the hosted check box cells will allow three check states rather than two.

ToolTipText

取得或設定供工具提示使用的文字。Gets or sets the text used for ToolTips.

(繼承來源 DataGridViewColumn)
TrueValue

取得或設定基礎值,其對應到以已核取的方塊形式出現的 true 儲存格值。Gets or sets the underlying value corresponding to a cell value of true, which appears as a checked box.

ValueType

取得或設定資枓行儲存格中的值之資料類型。Gets or sets the data type of the values in the column's cells.

(繼承來源 DataGridViewColumn)
Visible

取得或設定值,這個值指出是否看得到資料行。Gets or sets a value indicating whether the column is visible.

(繼承來源 DataGridViewColumn)
Width

取得或設定資料行的目前寬度。Gets or sets the current width of the column.

(繼承來源 DataGridViewColumn)

方法

Clone()

建立與這個群組列完全相同的複本。Creates an exact copy of this band.

(繼承來源 DataGridViewColumn)
Dispose()

釋放 DataGridViewBand 所使用的所有資源。Releases all resources used by the DataGridViewBand.

(繼承來源 DataGridViewBand)
Dispose(Boolean)

釋放 DataGridViewBand 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the DataGridViewBand and optionally releases the managed resources.

(繼承來源 DataGridViewColumn)
Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetPreferredWidth(DataGridViewAutoSizeColumnMode, Boolean)

根據指定的準則,計算資料行的理想寬度。Calculates the ideal width of the column based on the specified criteria.

(繼承來源 DataGridViewColumn)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
OnDataGridViewChanged()

當群組列與不同的 DataGridView 產生關聯時呼叫。Called when the band is associated with a different DataGridView.

(繼承來源 DataGridViewBand)
RaiseCellClick(DataGridViewCellEventArgs)

引發 CellClick 事件。Raises the CellClick event.

(繼承來源 DataGridViewElement)
RaiseCellContentClick(DataGridViewCellEventArgs)

引發 CellContentClick 事件。Raises the CellContentClick event.

(繼承來源 DataGridViewElement)
RaiseCellContentDoubleClick(DataGridViewCellEventArgs)

引發 CellContentDoubleClick 事件。Raises the CellContentDoubleClick event.

(繼承來源 DataGridViewElement)
RaiseCellValueChanged(DataGridViewCellEventArgs)

引發 CellValueChanged 事件。Raises the CellValueChanged event.

(繼承來源 DataGridViewElement)
RaiseDataError(DataGridViewDataErrorEventArgs)

引發 DataError 事件。Raises the DataError event.

(繼承來源 DataGridViewElement)
RaiseMouseWheel(MouseEventArgs)

引發 MouseWheel 事件。Raises the MouseWheel event.

(繼承來源 DataGridViewElement)
ToString()

取得描述資料行的字串。Gets a string that describes the column.

事件

Disposed

發生於處置 (Dispose) DataGridViewColumn 時。Occurs when the DataGridViewColumn is disposed.

(繼承來源 DataGridViewColumn)

適用於

另請參閱