Category / Section
How to select the whole row wherever you click in WinForms GridGroupingControl?
1 min read
Selection
When you set the ListBoxSelectionMode property, it selects the row on clicking on a cell and the current cell is active. This implies that, its background does not match the rest of the selected row.
To make the current cell look like the rest of the row, subscribe to the TableControlCurrentCellActivating event. In the handler, set e.Inner.ColIndex = 0. This sets the current cell on the header and not conflict with the rest of the selected row. The following code example is for changing the selection mode and CurrentCell.
C#
//Setting ListBoxSelectionMode this.gridGroupingControl1.TableDescriptor.TableOptions.ListBoxSelectionMode = SelectionMode.One; //Event triggered this.gridGroupingControl1.TableControlCurrentCellActivating += new Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCurrentCellActivatingEventHandler(this.gridGroupingControl1_TableControlCurrentCellActivating); private void gridGroupingControl1_TableControlCurrentCellActivating(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCurrentCellActivatingEventArgs e) { e.Inner.ColIndex = 0; }
VB
'Setting ListBoxSelectionMode Me.gridGroupingControl1.TableDescriptor.TableOptions.ListBoxSelectionMode = SelectionMode.One 'Event triggered Private Me.gridGroupingControl1.TableControlCurrentCellActivating += New Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCurrentCellActivatingEventHandler(AddressOf Me.gridGroupingControl1_TableControlCurrentCellActivating) Private Sub gridGroupingControl1_TableControlCurrentCellActivating(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCurrentCellActivatingEventArgs) e.Inner.ColIndex = 0 End Sub
The following screenshot illustrates the output.
Figure 1: Selecting the whole row on a single click
Samples:
C#: SelectingRow-C#
VB: SelectingRow-VB