System.Windows.Forms.DataGridViewCheckBoxCell Class

Displays a check box user interface (UI) to use in a System.Windows.Forms.DataGridView control.

See Also: DataGridViewCheckBoxCell Members

Syntax

public class DataGridViewCheckBoxCell : DataGridViewCell, IDataGridViewEditingCell

Remarks

The System.Windows.Forms.DataGridViewCheckBoxCell class is a specialized type of System.Windows.Forms.DataGridViewCell used to display binary or ternary information presented through a check box UI. In the default binary mode, the cells can hold values of true or false. In ternary mode, the cells take on one of the System.Windows.Forms.CheckState values. The DataGridViewCheckBoxCell.ThreeState property determines whether binary or ternary mode is in effect.

The System.Windows.Forms.DataGridViewCheckBoxColumn is the column type specialized to hold cells of this type. By default, the DataGridViewCheckBoxColumn.CellTemplate is initialized to a new System.Windows.Forms.DataGridViewCheckBoxCell. To pattern the cells within a column after an existing System.Windows.Forms.DataGridViewCheckBoxCell, set the column's DataGridViewCheckBoxColumn.CellTemplate property to the cell to use as a pattern.

The cell-related properties of the column are wrappers for the similarly-named properties of the template cell. Changing the property values of the template cell will affect only cells based on the template that are added after the change. Changing the cell-related property values of the column, however, will update the template cell and all other cells in the column, and refresh the column display if necessary.

When the current cell is a System.Windows.Forms.DataGridViewCheckBoxCell, the DataGridView.IsCurrentCellInEditMode property is always true.

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.CellClick 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(DataGridViewDataErrorContexts) method and pass in the DataGridViewDataErrorContexts.Commit value.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0