)
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 select the row while clicking on checkbox cell in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: April 18, 2016 |
Last Revised Date: December 24, 2019

Row selection

To select the row while clicking on the checkbox, the TableControlCheckBoxClick event can be handled. The SetSelected method can be used to select or deselect the row.

this.gridGroupingControl1.TableControlCheckBoxClick += new GridTableControlCellClickEventHandler(gridGroupingControl1_TableControlCheckBoxClick);
private void gridGroupingControl1_TableControlCheckBoxClick(object sender, GridTableControlCellClickEventArgs e)
{
    style = (GridTableCellStyleInfo)e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex);
    currentRecord = style.TableCellIdentity.DisplayElement.GetRecord();
    bool checkStatus = (style.Text == string.Empty || style.Text == "false");
    currentRecord.SetSelected(checkStatus);
}

 

Private Me.gridGroupingControl1.TableControlCheckBoxClick += New GridTableControlCellClickEventHandler(AddressOf gridGroupingControl1_TableControlCheckBoxClick)
Private Sub gridGroupingControl1_TableControlCheckBoxClick(ByVal sender As Object, ByVal e As GridTableControlCellClickEventArgs)
 style = CType(e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex), GridTableCellStyleInfo)
 currentRecord = style.TableCellIdentity.DisplayElement.GetRecord()
 Dim checkStatus As Boolean = (style.Text = String.Empty OrElse style.Text = "false")
 currentRecord.SetSelected(checkStatus)
End Sub

 

CurrentCellKeyDown event can be used for selecting the particular row by using space key on the checkbox.

this.gridGroupingControl1.TableControlCurrentCellKeyDown += gridGroupingControl1_TableControlCurrentCellKeyDown;
private void gridGroupingControl1_TableControlCurrentCellKeyDown(object sender, GridTableControlKeyEventArgs e)
{
    GridStyleInfo style = e.TableControl.CurrentCell.Renderer.CurrentStyle;
    // Make a selection while check the checkbox using key navigation
    if (e.Inner.KeyCode == Keys.Space && style.CellType == GridCellTypeName.CheckBox)
    {
        e.TableControl.RaiseCheckBoxClick(e.TableControl.CurrentCell.RowIndex, e.TableControl.CurrentCell.ColIndex, MouseEventArgs.Empty as MouseEventArgs);
    }
}  

 

Private Me.gridGroupingControl1.TableControlCurrentCellKeyDown += AddressOf gridGroupingControl1_TableControlCurrentCellKeyDown
Private Sub gridGroupingControl1_TableControlCurrentCellKeyDown(ByVal sender As Object, ByVal e As GridTableControlKeyEventArgs)
 Dim style As GridStyleInfo = e.TableControl.CurrentCell.Renderer.CurrentStyle
 ' Make a selection while check the checkbox using key navigation
 If e.Inner.KeyCode = Keys.Space AndAlso style.CellType Is GridCellTypeName.CheckBox Then
  e.TableControl.RaiseCheckBoxClick(e.TableControl.CurrentCell.RowIndex, e.TableControl.CurrentCell.ColIndex, TryCast(MouseEventArgs.Empty, MouseEventArgs))
 End If
End Sub

 

Screenshot

Shows the number of rows selected by clicking on checkbox cell

Samples:

C#: Row selection

VB: Row selection

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