How to change style of a selected row in WinForms GridGroupingControl?
Selection
To change the selected record’s text font, the QueryCellStylenfo event can be used. By default, WinForms GridGroupingControl have the two kinds of selections.
To change the selection back color when the selection is enabled by using AllowSelection property, AlphaBlendSelectionBackColor property of TableOptions can be used.
To change the selection back color when the selection is enabled by using ListBoxSelectionMode property, SelectionBackColor property of TableOptions can be used.
Using AllowSelection
C#
//Form() //Triggering the event. this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo); this.gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.Row | GridSelectionFlags.AlphaBlend; this.gridGroupingControl1.TableModel.Options.AlphaBlendSelectionColor = Color.Cyan; //Handling the event. void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) { int rowIndex = e.TableCellIdentity.RowIndex; if(e.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.Record && this.gridGroupingControl1.TableModel.SelectedRanges.Contains(GridRangeInfo.Row(rowIndex))) { e.Style.Font.Bold = true; e.Style.TextColor = Color.Blue; } }
VB
'Form() 'Triggering the event. Private Me.gridGroupingControl1.QueryCellStyleInfo += New GridTableCellStyleInfoEventHandler(AddressOf gridGroupingControl1_QueryCellStyleInfo) 'If AllowSelection property was used to enable the selection Me.gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.Row Or GridSelectionFlags.AlphaBlend Me.gridGroupingControl1.TableModel.Options.AlphaBlendSelectionColor = Color.Cyan 'Handling the event. Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs) Dim rowIndex As Integer = e.TableCellIdentity.RowIndex If e.TableCellIdentity.DisplayElement.Kind Is DisplayElementKind.Record AndAlso Me.gridGroupingControl1.TableModel.SelectedRanges.Contains(GridRangeInfo.Row(rowIndex)) Then e.Style.Font.Bold = True e.Style.TextColor = Color.Blue End If End Sub
Using ListBoxSelectionMode
C#
//Form() //Triggering the event. this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo); this.gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.One; this.gridGroupingControl1.TableOptions.SelectionBackColor = Color.Cyan; //Handling the event. void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) { if(e.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.Record && e.TableCellIdentity.DisplayElement.GetRecord().IsSelected()) { e.Style.Font.Bold = true; e.Style.TextColor = Color.Blue; } }
VB
'Form() 'Triggering the event. Private Me.gridGroupingControl1.QueryCellStyleInfo += New GridTableCellStyleInfoEventHandler(AddressOf gridGroupingControl1_QueryCellStyleInfo) Me.gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.One Me.gridGroupingControl1.TableOptions.SelectionBackColor = Color.Cyan 'Handling the event. Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs) If e.TableCellIdentity.DisplayElement.Kind Is DisplayElementKind.Record AndAlso e.TableCellIdentity.DisplayElement.GetRecord().IsSelected() Then e.Style.Font.Bold = True e.Style.TextColor = Color.Blue End If End Sub
Screenshot
Samples:
Conclusion
I hope you enjoyed learning about how to change style of a selected row in WinForms GridGroupingControl.
You can refer to our WinForms GridGroupingControl feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridGroupingControl documentation to understand how to create and manipulate data.
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!