DataGridViewCheckBoxColumn Class
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.
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 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
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Reference
DataGridViewCheckBoxColumn MembersSystem.Windows.Forms Namespace
DataGridView Class
DataGridViewColumn
DataGridViewRow
DataGridViewCheckBoxCell Class
CheckBox Class
DataGridViewColumn.SortMode
DataGridView.CellClick Event
DataGridView.CellValueChanged Event
DataGridView.CurrentCellDirtyStateChanged Event
DataGridView.CommitEdit