DataGridViewCheckBoxCell 類別

定義

顯示用於 DataGridView 控制項中的核取方塊使用者介面 (UI)。

public ref class DataGridViewCheckBoxCell : System::Windows::Forms::DataGridViewCell, System::Windows::Forms::IDataGridViewEditingCell
public class DataGridViewCheckBoxCell : System.Windows.Forms.DataGridViewCell, System.Windows.Forms.IDataGridViewEditingCell
type DataGridViewCheckBoxCell = class
    inherit DataGridViewCell
    interface IDataGridViewEditingCell
Public Class DataGridViewCheckBoxCell
Inherits DataGridViewCell
Implements IDataGridViewEditingCell
繼承
DataGridViewCheckBoxCell
實作

範例

下列程式碼範例會使用 來 DataGridViewCheckBoxColumn 追蹤哪些員工在辦公室中。 資料行是由 物件所 DataGridViewCheckBoxCell 組成。 此範例是類別概觀主題中較大範例的 DataGridViewComboBoxColumn 一部分。

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

備註

類別 DataGridViewCheckBoxCell 是特製化的 類型 DataGridViewCell ,用來顯示透過核取方塊 UI 呈現的二進位或三元資訊。 在預設二進位模式中,儲存格可以保存 或 false 的值 true 。 在三元模式中,儲存格會採用其中 CheckState 一個值。 屬性 ThreeState 會判斷二元或三元模式是否有效。

DataGridViewCheckBoxColumn是特製化用來保存此類型儲存格的資料行類型。 根據預設,會 DataGridViewCheckBoxColumn.CellTemplate 初始化為新的 DataGridViewCheckBoxCell 。 若要在現有 DataGridViewCheckBoxCell 之後建立資料行內儲存格的圖樣,請將資料 CellTemplate 行的 屬性設定為要當做圖樣使用的儲存格。

資料行的儲存格相關屬性是樣板儲存格類似名稱屬性的包裝函式。 變更範本儲存格的屬性值只會根據變更之後新增的範本影響儲存格。 不過,變更資料行的資料格相關屬性值將會更新範本儲存格和資料行中的所有其他儲存格,並視需要重新整理資料行顯示。

當目前儲存格為 DataGridViewCheckBoxCell 時, DataGridView.IsCurrentCellInEditMode 屬性一律 true 為 。

一般而言,核取方塊儲存格值適用于儲存體,就像任何其他資料一樣,或用於執行大量作業。 如果您想要在使用者按一下核取方塊儲存格時立即回應,您可以處理 DataGridView.CellClick 事件,但此事件會在資料格值更新之前發生。 如果您需要按一下時的新值,其中一個選項是根據目前的值來計算預期的值。 另一種方法是立即認可變更,並處理 DataGridView.CellValueChanged 事件以回應變更。 若要在按一下儲存格時認可變更,您必須處理 DataGridView.CurrentCellDirtyStateChanged 事件。 在處理常式中,如果目前的儲存格是核取方塊儲存格,請呼叫 DataGridView.CommitEdit 方法並傳入 Commit 值。

給繼承者的注意事項

當您衍生自 DataGridViewCheckBoxCell 並新增屬性至衍生類別時,請務必覆寫 Clone() 方法,以在複製作業期間複製新屬性。 您也應該呼叫基類 Clone() 的 方法,以便基類的屬性複製到新的儲存格。

建構函式

DataGridViewCheckBoxCell()

DataGridViewCheckBoxCell 類別的新執行個體初始化為預設狀態。

DataGridViewCheckBoxCell(Boolean)

初始化 DataGridViewCheckBoxCell 類別的新執行個體,以啟用二進位或三元狀態。

屬性

AccessibilityObject

取得指定給 DataGridViewCell.DataGridViewCellAccessibleObjectDataGridViewCell

(繼承來源 DataGridViewCell)
ColumnIndex

取得這個儲存格的資料行索引。

(繼承來源 DataGridViewCell)
ContentBounds

取得圍住儲存格內容區域的周框。

(繼承來源 DataGridViewCell)
ContextMenuStrip

取得或設定與儲存格相關聯的捷徑功能表。

(繼承來源 DataGridViewCell)
DataGridView

取得與這個項目有關聯的 DataGridView 控制項。

(繼承來源 DataGridViewElement)
DefaultNewRowValue

取得新資料錄之資料列中儲存格的預設值。

(繼承來源 DataGridViewCell)
Displayed

取得值,該值表示儲存格目前是否顯示於螢幕上。

(繼承來源 DataGridViewCell)
EditedFormattedValue

取得目前已格式化的儲存格值,不管儲存格是否處於編輯模式,而值是否尚未認可。

(繼承來源 DataGridViewCell)
EditingCellFormattedValue

取得或設定當控制項在編輯模式中時,由儲存格所裝載的控制項之格式化值。

EditingCellValueChanged

取得或設定旗標,表示此儲存格已經變更值。

EditType

取得儲存格的裝載編輯控制項型別。

ErrorIconBounds

取得儲存格之錯誤圖示的界限。

(繼承來源 DataGridViewCell)
ErrorText

取得或設定文字,描述與儲存格相關聯的錯誤狀況。

(繼承來源 DataGridViewCell)
FalseValue

取得或設定對應到 false 的儲存格值的基礎值。

FlatStyle

取得或設定核取方塊使用者介面 (UI) 的平面樣式外觀。

FormattedValue

取得儲存格的格式化值,以供顯示。

(繼承來源 DataGridViewCell)
FormattedValueType

取得儲存格顯示值的型別。

Frozen

取得指出是否已凍結此儲存格的值。

(繼承來源 DataGridViewCell)
HasStyle

取得指出是否已經設定 Style 屬性的值。

(繼承來源 DataGridViewCell)
IndeterminateValue

取得或設定對應到不定或 null 的儲存格值的基礎值。

InheritedState

取得儲存格的目前狀態,是繼承其資料列和資料行的狀態。

(繼承來源 DataGridViewCell)
InheritedStyle

取得目前套用至儲存格的樣式。

(繼承來源 DataGridViewCell)
IsInEditMode

取得指出目前是否正在編輯這個儲存格的值。

(繼承來源 DataGridViewCell)
OwningColumn

取得包含這個儲存格的資料行。

(繼承來源 DataGridViewCell)
OwningRow

取得包含這個儲存格的資料列。

(繼承來源 DataGridViewCell)
PreferredSize

取得能夠容納儲存格的矩形區域大小 (以像素為單位)。

(繼承來源 DataGridViewCell)
ReadOnly

取得或設定值,指出是否可以編輯儲存格的資料。

(繼承來源 DataGridViewCell)
Resizable

取得指出儲存格是否可以調整大小的值。

(繼承來源 DataGridViewCell)
RowIndex

取得儲存格的父資料列索引。

(繼承來源 DataGridViewCell)
Selected

取得或設定值,指出是否已選取此儲存格。

(繼承來源 DataGridViewCell)
Size

取得儲存格的大小。

(繼承來源 DataGridViewCell)
State

取得此項目的使用者介面 (UI) 狀態。

(繼承來源 DataGridViewElement)
Style

取得或設定儲存格的樣式。

(繼承來源 DataGridViewCell)
Tag

取得或設定物件,其中包含儲存格的相關補充資料。

(繼承來源 DataGridViewCell)
ThreeState

取得或設定值,指出是否已針對裝載的核取方塊控制項啟用三元模式。

ToolTipText

取得或設定與這個儲存格相關聯的工具提示文字。

(繼承來源 DataGridViewCell)
TrueValue

取得或設定對應到 true 的儲存格值的基礎值。

Value

取得或設定與這個儲存格相關聯的值。

(繼承來源 DataGridViewCell)
ValueType

取得儲存格中的值之資料型別。

Visible

取得指出儲存格是在已隱藏資料列或是資料行中的值。

(繼承來源 DataGridViewCell)

方法

AdjustCellBorderStyle(DataGridViewAdvancedBorderStyle, DataGridViewAdvancedBorderStyle, Boolean, Boolean, Boolean, Boolean)

根據指定的準則,修改輸入儲存格框線樣式。

(繼承來源 DataGridViewCell)
BorderWidths(DataGridViewAdvancedBorderStyle)

傳回 Rectangle,表示所有儲存格邊界的寬度。

(繼承來源 DataGridViewCell)
ClickUnsharesRow(DataGridViewCellEventArgs)

指出當按下儲存格時,儲存格的資料列是否會取消共用。

(繼承來源 DataGridViewCell)
Clone()

建立與這個儲存格完全相同的複本。

ContentClickUnsharesRow(DataGridViewCellEventArgs)

指出當按下儲存格內容時,包含儲存格的資料列是否會取消共用。

ContentDoubleClickUnsharesRow(DataGridViewCellEventArgs)

指出當按兩下儲存格內容時,包含儲存格的資料列是否會取消共用。

CreateAccessibilityInstance()

DataGridViewCheckBoxCell 建立新的可存取物件。

DetachEditingControl()

DataGridView 中移除儲存格的編輯控制項。

(繼承來源 DataGridViewCell)
Dispose()

釋放 DataGridViewCell 所使用的所有資源。

(繼承來源 DataGridViewCell)
Dispose(Boolean)

釋放 DataGridViewCell 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

(繼承來源 DataGridViewCell)
DoubleClickUnsharesRow(DataGridViewCellEventArgs)

指出當按兩下儲存格時,儲存格的資料列是否會取消共用。

(繼承來源 DataGridViewCell)
EnterUnsharesRow(Int32, Boolean)

指出當焦點移至儲存格時,是否將取消共用父資料列。

(繼承來源 DataGridViewCell)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetClipboardContent(Int32, Boolean, Boolean, Boolean, Boolean, String)

擷取儲存格的已格式化的值,以複製到 Clipboard

(繼承來源 DataGridViewCell)
GetContentBounds(Graphics, DataGridViewCellStyle, Int32)

傳回圍住儲存格內容區域的週框,這個內容區域是使用指定的 Graphics 和儲存格樣式所計算。

GetContentBounds(Int32)

使用預設的 Graphics 和目前儲存格中所採用的儲存格樣式,傳回圍住儲存格內容區域的周框。

(繼承來源 DataGridViewCell)
GetEditedFormattedValue(Int32, DataGridViewDataErrorContexts)

傳回目前已格式化的儲存格值,不管儲存格是否處於編輯模式,而值是否尚未認可。

(繼承來源 DataGridViewCell)
GetEditingCellFormattedValue(DataGridViewDataErrorContexts)

取得儲存格處於編輯模式時的格式值。

GetErrorIconBounds(Graphics, DataGridViewCellStyle, Int32)

傳回圍住儲存格的錯誤圖示之週框 (如果有此圖示)。

GetErrorText(Int32)

傳回表示儲存格錯誤的字串。

(繼承來源 DataGridViewCell)
GetFormattedValue(Object, Int32, DataGridViewCellStyle, TypeConverter, TypeConverter, DataGridViewDataErrorContexts)

取得儲存格資料的格式化值。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetInheritedContextMenuStrip(Int32)

取得目前儲存格的繼承捷徑功能表。

(繼承來源 DataGridViewCell)
GetInheritedState(Int32)

傳回值,指出儲存格的目前狀態是從其資料列和資料行的狀態繼承而來。

(繼承來源 DataGridViewCell)
GetInheritedStyle(DataGridViewCellStyle, Int32, Boolean)

取得套用到儲存格的樣式。

(繼承來源 DataGridViewCell)
GetPreferredSize(Graphics, DataGridViewCellStyle, Int32, Size)

計算儲存格的慣用大小 (以像素為單位)。

GetSize(Int32)

取得儲存格的大小。

(繼承來源 DataGridViewCell)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetValue(Int32)

取得儲存格的值。

(繼承來源 DataGridViewCell)
InitializeEditingControl(Int32, Object, DataGridViewCellStyle)

初始化用來編輯儲存格的控制項。

(繼承來源 DataGridViewCell)
KeyDownUnsharesRow(KeyEventArgs, Int32)

指出當儲存格具有焦點而按下按鍵時,包含儲存格的資料列是否會取消共用。

KeyEntersEditMode(KeyEventArgs)

判斷是否應該根據指定的按鍵啟動編輯模式。

(繼承來源 DataGridViewCell)
KeyPressUnsharesRow(KeyPressEventArgs, Int32)

指出如果當焦點在資料列中的儲存格時按下按鍵,是否會取消資料列的共用。

(繼承來源 DataGridViewCell)
KeyUpUnsharesRow(KeyEventArgs, Int32)

指出當儲存格具有焦點而放開按鍵時,包含儲存格的資料列是否會取消共用。

LeaveUnsharesRow(Int32, Boolean)

指出當焦點移出資料列中的儲存格時,是否取消共用該資料列。

(繼承來源 DataGridViewCell)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MouseClickUnsharesRow(DataGridViewCellMouseEventArgs)

指出當指標在資料列的儲存格上,而使用者按一下滑鼠按鈕時,該資料列是否取消共用。

(繼承來源 DataGridViewCell)
MouseDoubleClickUnsharesRow(DataGridViewCellMouseEventArgs)

指出當使用者按兩下資料列中的儲存格時,是否取消共用該資料列。

(繼承來源 DataGridViewCell)
MouseDownUnsharesRow(DataGridViewCellMouseEventArgs)

指出當滑鼠指標在儲存格上方而按下滑鼠按鈕時,包含儲存格的資料列是否會取消共用。

MouseEnterUnsharesRow(Int32)

指出當滑鼠指標位在儲存格上方時,包含儲存格的資料列是否會取消共用。

MouseLeaveUnsharesRow(Int32)

指出當滑鼠指標離開儲存格時,包含儲存格的資料列是否會取消共用。

MouseMoveUnsharesRow(DataGridViewCellMouseEventArgs)

指出當滑鼠指標移到某資料列的儲存格上方時,是否取消共用該資料列。

(繼承來源 DataGridViewCell)
MouseUpUnsharesRow(DataGridViewCellMouseEventArgs)

指出當滑鼠指標在儲存格上方而放開滑鼠按鈕時,包含儲存格的資料列是否會取消共用。

OnClick(DataGridViewCellEventArgs)

當按下儲存格時呼叫。

(繼承來源 DataGridViewCell)
OnContentClick(DataGridViewCellEventArgs)

當按下儲存格內容時呼叫。

OnContentDoubleClick(DataGridViewCellEventArgs)

當按兩下儲存格內容時呼叫。

OnDataGridViewChanged()

當儲存格的 DataGridView 屬性變更時呼叫。

(繼承來源 DataGridViewCell)
OnDoubleClick(DataGridViewCellEventArgs)

當按兩下儲存格時呼叫。

(繼承來源 DataGridViewCell)
OnEnter(Int32, Boolean)

當焦點移至儲存格時呼叫。

(繼承來源 DataGridViewCell)
OnKeyDown(KeyEventArgs, Int32)

當焦點在儲存格上,按下字元鍵時即會呼叫。

OnKeyPress(KeyPressEventArgs, Int32)

當焦點在儲存格上,按下按鍵時呼叫。

(繼承來源 DataGridViewCell)
OnKeyUp(KeyEventArgs, Int32)

當焦點在儲存格上,放開字元鍵時呼叫。

OnLeave(Int32, Boolean)

當焦點從儲存格移動時呼叫。

OnMouseClick(DataGridViewCellMouseEventArgs)

當滑鼠指標在儲存格上,使用者按一下滑鼠按鈕時呼叫。

(繼承來源 DataGridViewCell)
OnMouseDoubleClick(DataGridViewCellMouseEventArgs)

當滑鼠指標在儲存格上,使用者按兩下滑鼠按鈕時呼叫。

(繼承來源 DataGridViewCell)
OnMouseDown(DataGridViewCellMouseEventArgs)

當指標位於儲存格上,按住滑鼠按鈕時即會呼叫。

OnMouseEnter(Int32)

當滑鼠指標移到儲存格上方時呼叫。

(繼承來源 DataGridViewCell)
OnMouseLeave(Int32)

當滑鼠指標從儲存格移動時即會呼叫。

OnMouseMove(DataGridViewCellMouseEventArgs)

當滑鼠指標移到儲存格內時呼叫。

OnMouseUp(DataGridViewCellMouseEventArgs)

當滑鼠指標位於儲存格上,放開滑鼠按鈕時即會呼叫。

Paint(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Object, Object, String, DataGridViewCellStyle, DataGridViewAdvancedBorderStyle, DataGridViewPaintParts)

繪製目前的 DataGridViewCheckBoxCell

PaintBorder(Graphics, Rectangle, Rectangle, DataGridViewCellStyle, DataGridViewAdvancedBorderStyle)

繪製目前 DataGridViewCell 的框線。

(繼承來源 DataGridViewCell)
PaintErrorIcon(Graphics, Rectangle, Rectangle, String)

繪製目前 DataGridViewCell 的錯誤圖示。

(繼承來源 DataGridViewCell)
ParseFormattedValue(Object, DataGridViewCellStyle, TypeConverter, TypeConverter)

將為了顯示而格式化的值轉換成實際的儲存格值。

PositionEditingControl(Boolean, Boolean, Rectangle, Rectangle, DataGridViewCellStyle, Boolean, Boolean, Boolean, Boolean)

設定由 DataGridView 控制項中的儲存格裝載之編輯控制項的位置和大小。

(繼承來源 DataGridViewCell)
PositionEditingPanel(Rectangle, Rectangle, DataGridViewCellStyle, Boolean, Boolean, Boolean, Boolean)

設定由儲存格裝載之編輯面板的位置和大小,並傳回編輯面板中編輯控制項的標準界限。

(繼承來源 DataGridViewCell)
PrepareEditingCellForEdit(Boolean)

此方法對這個型別來說不具意義。

RaiseCellClick(DataGridViewCellEventArgs)

引發 CellClick 事件。

(繼承來源 DataGridViewElement)
RaiseCellContentClick(DataGridViewCellEventArgs)

引發 CellContentClick 事件。

(繼承來源 DataGridViewElement)
RaiseCellContentDoubleClick(DataGridViewCellEventArgs)

引發 CellContentDoubleClick 事件。

(繼承來源 DataGridViewElement)
RaiseCellValueChanged(DataGridViewCellEventArgs)

引發 CellValueChanged 事件。

(繼承來源 DataGridViewElement)
RaiseDataError(DataGridViewDataErrorEventArgs)

引發 DataError 事件。

(繼承來源 DataGridViewElement)
RaiseMouseWheel(MouseEventArgs)

引發 MouseWheel 事件。

(繼承來源 DataGridViewElement)
SetValue(Int32, Object)

設定儲存格的值。

(繼承來源 DataGridViewCell)
ToString()

傳回儲存格的字串表示。

適用於

另請參閱