DataGridViewCheckBoxColumn クラス
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


DataGridViewCheckBoxColumn クラスは、DataGridViewColumn クラスの特殊な型で、2 進数の状態を示すセルを論理的にホストするために使用されます。DataGridViewCheckBoxColumn には、それと交差するすべての DataGridViewRow 内に、関連付けられた DataGridViewCheckBoxCell があります。各セルには、CheckBox コントロールに似たユーザー インターフェイス (UI) があります。
この列型の既定の並べ替えモードは、NotSortable です。
通常、チェック ボックス セルの値は、他のデータと同様に情報を格納したり、一括操作を実行したりする目的で使用されます。ユーザーがチェック ボックス セルをクリックしたときに直ちに応答する場合は、DataGridView.CellContentClick イベントを処理しますが、このイベントはセル値が更新される前に発生します。クリック時に新しい値が必要な場合は、現在の値を基に期待される値を計算するという方法が考えられます。また別の方法として、変更を直ちにコミットし、DataGridView.CellValueChanged イベントを処理してその変更に応答することも考えられます。セルがクリックされたときに変更をコミットするには、DataGridView.CurrentCellDirtyStateChanged イベントを処理する必要があります。現在のセルがチェック ボックス セルである場合、ハンドラで DataGridView.CommitEdit メソッドを呼び出し、Commit の値を渡します。
継承時の注意 DataGridViewCheckBoxColumn からクラスを派生させて新しいプロパティを追加する場合は、Clone メソッドをオーバーライドして、クローン操作時に新しいプロパティをコピーする必要があります。また、基本クラスの Clone メソッドも呼び出して、基本クラスのプロパティが新しいセルにコピーされるようにする必要があります。
次のコード例は、DataGridViewCheckBoxColumn を使用して、外出している従業員をマークする方法を示しています。
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
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: 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); }

System.Windows.Forms.DataGridViewElement
System.Windows.Forms.DataGridViewBand
System.Windows.Forms.DataGridViewColumn
System.Windows.Forms.DataGridViewCheckBoxColumn


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridViewCheckBoxColumn メンバ
System.Windows.Forms 名前空間
DataGridView クラス
DataGridViewColumn
DataGridViewRow
DataGridViewCheckBoxCell クラス
CheckBox クラス
DataGridViewColumn.SortMode
DataGridView.CellClick イベント
DataGridView.CellValueChanged イベント
DataGridView.CurrentCellDirtyStateChanged イベント
DataGridView.CommitEdit
- DataGridViewCheckBoxColumn クラスのページへのリンク