Articles in this section
Category / Section

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

2 mins read

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.

Alert message on clicking the CheckBox in Winforms GridControl

 

Conclusion

I hope you enjoyed learning about how to restrict the CheckBox from being checked in WinForms GridControl.

You can refer to our  WinForms GridControl feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridControl documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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