2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
SelectionTo change the selected record’s text font, the QueryCellStylenfo event can be used. By default, 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: |
2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.
This code is not working as expected when I change AllowSelection property as below
this.grid1.TableOptions.AllowSelection = Syncfusion.Windows.Forms.Grid.GridSelectionFlags.Row;
Hi Hanuman,
Thanks for your feedback.
We have modified the document with proper details and published successfully.
Please let us know if you have any queries.
Regards,
Piruthiviraj