How to use the CheckBoxClick event when the CheckBox state changes by space key in WinForms GridControl?
Events
In the WinForms GridControl, by default CheckBoxClick event is raised, when you change the CheckBox state on Mousecklick. On using the space key, the CheckBox state is changed, but the CheckBoxClick event is not fired. To resolve this, the CheckBoxClick event can be manually raised by using the RaiseCheckBoxClick method. This method is called by using the CurrentCellKeyDown event.
The following code example is for calling the CheckBoxClick event in the CurrentCellKeyDown event.
C#
// Hooks the CheckBoxClick event this.gridControl1.CheckBoxClick += new GridCellClickEventHandler(gridControl1_CheckBoxClick); // Hooks the CurrentCellKeyDown event this.gridControl1.CurrentCellKeyDown += new KeyEventHandler(gridControl1_CurrentCellKeyDown); void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e) { // validates the Key pressed. if (e.KeyCode == Keys.Space) { GridCurrentCell cc=this.gridControl1.CurrentCell ; if (this.gridControl1[this.gridControl1.CurrentCell.RowIndex, this.gridControl1.CurrentCell.ColIndex].CellType == GridCellTypeName.CheckBox) { //Raises the CheckBoxClick event. this.gridControl1.RaiseCheckBoxClick(cc.RowIndex, cc.ColIndex, MouseEventArgs.Empty as MouseEventArgs); } } } void gridControl1_CheckBoxClick(object sender, GridCellClickEventArgs e) { Debugger.Break(); }
VB
' Hooks the CheckBoxClick event AddHandler gridControl1.CheckBoxClick, AddressOf gridControl1_CheckBoxClick ' Hooks the CurrentCellKeyDown event AddHandler gridControl1.CurrentCellKeyDown, AddressOf gridControl1_CurrentCellKeyDown Private Sub gridControl1_CurrentCellKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) 'validates the Key pressed. If e.KeyCode = Keys.Space Then Dim cc As GridCurrentCell=Me.gridControl1.CurrentCell If Me.gridControl1(Me.gridControl1.CurrentCell.RowIndex, Me.gridControl1.CurrentCell.ColIndex).CellType Is GridCellTypeName.CheckBox Then 'Raises the CheckBoxClick event. Me.gridControl1.RaiseCheckBoxClick(cc.RowIndex, cc.ColIndex, TryCast(MouseEventArgs.Empty, MouseEventArgs)) End If End If End Sub Private Sub gridControl1_CheckBoxClick(ByVal sender As Object, ByVal e As GridCellClickEventArgs) Debugger.Break() End Sub
Here MouseEventArgs are passed as Empty to the CheckBoxClick event. So, in this case, you can’t use mouse arguments inside the CheckBoxClick event.
Samples:
I hope you enjoyed learning about how to use the CheckBoxClick event when the CheckBox state changes by space key in WinForms GridControl.
You can refer to our WinForms GridControl’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridControl documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms 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 WinForms GridControl and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!