Articles in this section
Category / Section

How to select the record row while clicking on checkbox cell in WinForms GridGroupingControl?

1 min read

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

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied