Articles in this section
Category / Section

What is the purpose of the CheckBoxOptions property in WinForms GridControl?

6 mins read

Purpose of checkbox option

The CheckBoxOptions.CheckedValue specifies the value to be given in the CellValue to check the checkbox, that is, either 1 or true. For example, when you want true to be checked and false to be unchecked.

By using GridModel

C#

// Change cell type to CheckBox
this.gridControl1[2, 3].CellType = "CheckBox";
// Set the values for ChekedValue and UncheckedValue
this.gridControl1[2, 3].CheckBoxOptions.CheckedValue = "true";
this.gridControl1[2, 3].CheckBoxOptions.UncheckedValue = "false";
// Set the CellValueType as bool.
this.gridControl1[2, 3].CellValueType = typeof(bool);
// set CellValue as true;
this.gridControl1[2, 3].CellValue = true;
// Add the description to the checkBox
this.gridControl1[2, 3].Description = "Click Me";

 

VB

' Change cell type to CheckBox
Me.gridControl1(2, 3).CellType = "CheckBox"
' Set the values for ChekedValue and UncheckedValue
Me.gridControl1(2, 3).CheckBoxOptions.CheckedValue = "true"
Me.gridControl1(2, 3).CheckBoxOptions.UncheckedValue = "false"
' Set the CellValueType as bool.
Me.gridControl1(2, 3).CellValueType = GetType(Boolean)
' set CellValue as true;
Me.gridControl1(2, 3).CellValue = True
' Add the description to the checkBox
Me.gridControl1(2, 3).Description = "Click Me"

 

By using QueryCellInfo event

C#

void gridControl1_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
    if(e.RowIndex==2 && e.ColIndex == 4)
    {
        //Change cell type to CheckBox
        e.Style.CellType = "CheckBox";
        // Set the values for ChekedValue and UncheckedValue 
        e.Style.CheckBoxOptions.CheckedValue = "true";
        e.Style.CheckBoxOptions.UncheckedValue = "false";
        // Set the CellValueType as bool.
        e.Style.CellValueType = typeof(bool);
        // Add the description to the checkBox
        e.Style.Description = "Enable";
    }
}

 

VB

Private Sub gridControl1_QueryCellInfo(ByVal sender As Object, ByVal e As GridQueryCellInfoEventArgs)
    If e.RowIndex=2 AndAlso e.ColIndex = 4 Then
        'Change cell type to CheckBox
        e.Style.CellType = "CheckBox"
        ' Set the values for ChekedValue and UncheckedValue
        e.Style.CheckBoxOptions.CheckedValue = "true"
        e.Style.CheckBoxOptions.UncheckedValue = "false"
        ' Set the CellValueType as bool.
        e.Style.CellValueType = GetType(Boolean)
        ' Add the description to the checkBox
        e.Style.Description = "Enable"
    End If
End Sub

 

Note:

Instead of true and false, you can also set 1 and 0 respectively to check and uncheck values in the similar way.

 

The following screenshot displays the CheckBox cell by using the CheckBoxOptions.

 Show the checkbox option in grid

 

Samples:

C#: CheckBoxOptionsProperty

VB: CheckBoxOptionsProperty

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied