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

Platform: WinForms |
Control: GridGroupingControl |
Published Date: November 13, 2015 |
Last Revised Date: December 23, 2019

Select the record using checkbox

To select or deselect the whole row or record while checking or unchecking the check box, the method SetSelected can be used through TableControlCheckBoxClick event. To have the same behavior by pressing Space key on the checkbox, TableControlCurrentCellKeyDown event is handled.

C#

this.gridGroupingControl1.TableControlCheckBoxClick += new GridTableControlCellClickEventHandler(gridGroupingControl1_TableControlCheckBoxClick);
this.gridGroupingControl1.TableControlCurrentCellKeyDown += gridGroupingControl1_TableControlCurrentCellKeyDown;
 
void gridGroupingControl1_TableControlCheckBoxClick(object sender, GridTableControlCellClickEventArgs e)
{
    GridTableCellStyleInfo style = (GridTableCellStyleInfo)e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex);
    Record currentRecord = style.TableCellIdentity.DisplayElement.GetRecord();
    // Selection added for current record
    if (this.gridGroupingControl1.TableModel[e.Inner.RowIndex, e.Inner.ColIndex].Text == "False")
currentRecord.SetSelected(style.Text == "False");
}
 
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 );
                
    }
}

 

VB

AddHandler gridGroupingControl1.TableControlCheckBoxClick, AddressOf gridGroupingControl1_TableControlCheckBoxClick
AddHandler Me.gridGroupingControl1.TableControlCurrentCellKeyDown, AddressOf gridGroupingControl1_TableControlCurrentCellKeyDown
 
Private Sub gridGroupingControl1_TableControlCheckBoxClick(ByVal sender As Object, ByVal e As GridTableControlCellClickEventArgs)
    Dim style As GridTableCellStyleInfo = CType(e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex), GridTableCellStyleInfo)
    Dim currentRecord As Record = style.TableCellIdentity.DisplayElement.GetRecord()
    ‘ Selection added for current record
    If Me.gridGroupingControl1.TableModel(e.Inner.RowIndex, e.Inner.ColIndex).Text = "False" Then
    currentRecord.SetSelected(style.Text = "False")
    End If
End Sub
 
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

 

Image:

Select the row using checkbox cell

 

Samples:

C#: Select Record

VB: Select Record

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Hossam
May 23, 2017
Record Selection works perfectly , but when i click a checkbox cell , it clears the other checkbox cell on other rows ,why? Reply

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