Articles in this section

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.

 

// 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();
}
' 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

Note:

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:

C#: CheckBoxClickEvent_C#

VB: CheckBoxClickEvent_VB

 

Conclusion

I hope you enjoyed learning about how to use the CheckBoxClick event when the CheckBox state changes by the space key in the WinForms GridControl.


You can refer to our WinForms GridControl feature tour page to know about its other groundbreaking feature representations and WinForms GridControl documentation, and how to quickly get started for configuration specifications.


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 forums, Direct-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)
Access denied
Access denied