DataGridViewCheckBoxColumn Class
Hosts a collection of DataGridViewCheckBoxCell objects.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The DataGridViewCheckBoxColumn class is a specialized type of the DataGridViewColumn class used to logically host cells that indicate binary state. A DataGridViewCheckBoxColumn has an associated DataGridViewCheckBoxCell in every DataGridViewRow that intersects it. Each cell supplies a user interface (UI) that is similar to a CheckBox control.
The 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. 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. Another approach is to commit the change immediately, and handle the DataGridView.CellValueChanged event to respond to it. To commit the change when the cell is clicked, you must handle the DataGridView.CurrentCellDirtyStateChanged event. In the handler, if the current cell is a check box cell, call the DataGridView.CommitEdit method and pass in the Commit value.
Notes to Inheritors: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. You should also call the base class's Clone method so that the properties of the base class are copied to the new cell.
The following code example demonstrates how to use a DataGridViewCheckBoxColumn to mark which employees are out of the office. This example is part of a larger example available in the DataGridViewComboBoxColumn class overview topic.
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
System.Windows.Forms.DataGridViewElement
System.Windows.Forms.DataGridViewBand
System.Windows.Forms.DataGridViewColumn
System.Windows.Forms.DataGridViewCheckBoxColumn
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.