)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to restrict the CheckBox from being checked or unchecked in WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: April 25, 2015 |
Last Revised Date: December 20, 2019
Tags: checkbox

Restrict the checkbox option

The CheckBox options can be restricted from being changed to the checked or unchecked state by using the CheckBoxClick event when the CheckBox cell is clicked. In the given sample, a message box shows up while clicking on the restricted CheckBox cell.

C#

//CheckBox cell. 
this.gridControl1[2, 2].CellType = "CheckBox";
this.gridControl1[2, 2].CheckBoxOptions = new GridCheckBoxCellInfo("true", "false", "false", true);
this.gridControl1[2, 2].CellValue = true;
this.gridControl1[2, 2].Description = "Restricted";
this.gridControl1[2, 4].CellType = "CheckBox";
this.gridControl1[2, 4].CheckBoxOptions = new GridCheckBoxCellInfo("true", "false", "false", true);
this.gridControl1[2, 4].CellValue = true;
this.gridControl1[2, 4].Description = "Enabled";
//Hooks the event in the Form_Load to restrict the CheckBox options from being clicked.
this.gridControl1.CheckBoxClick += gridControl1_CheckBoxClick;
void gridControl1_CheckBoxClick(object sender, Syncfusion.Windows.Forms.Grid.GridCellClickEventArgs e)
{
    //Restricts the checkbox cell at [2,2] from clicking the options.
    if (e.RowIndex == 2 && e.ColIndex == 2)
    {
        MessageBox.Show("The CheckBox options are restricted");
        //Cancels the CheckBox click event.
        e.Cancel = true;
    }
}

VB

'CheckBox cell.
Private Me.gridControl1(2, 2).CellType = "CheckBox"
Private Me.gridControl1(2, 2).CheckBoxOptions = New GridCheckBoxCellInfo("true", "false", "false", True)
Private Me.gridControl1(2, 2).CellValue = True
Private Me.gridControl1(2, 2).Description = "Restricted"
Private Me.gridControl1(2, 4).CellType = "CheckBox"
Private Me.gridControl1(2, 4).CheckBoxOptions = New GridCheckBoxCellInfo("true", "false", "false", True)
Private Me.gridControl1(2, 4).CellValue = True
Private Me.gridControl1(2, 4).Description = "Enabled"
'Hooks the event in the Form_Load to restrict the CheckBox options from being clicked.
Private Me.gridControl1.CheckBoxClick += AddressOf gridControl1_CheckBoxClick
Private Sub gridControl1_CheckBoxClick(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCellClickEventArgs)
    'Restricts the checkbox cell at [2,2] from clicking the options.
    If e.RowIndex = 2 AndAlso e.ColIndex = 2 Then
        MessageBox.Show("The CheckBox options are restricted")
        'Cancels the CheckBox click event.
        e.Cancel = True
    End If
End Sub

 

The following image shows the alert message on clicking the CheckBox option.

Hide the checkbox click event

 

Note:

In the given sample, the options are prevented while clicking on the CheckBox, but the CheckBox option can be changed by using the space bar.

 

Samples:

C#: CheckBoxClickEvent

VB: CheckBoxClickEvent

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon