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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to change the style of a selected row in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl
Tags: selection, row, styles

Selection

To 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

change the style of a selected row

Samples:

C#: Display Behavior CS

VB: Display Behavior VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
hanuman
Oct 31, 2017

This code is not working as expected when I change AllowSelection property as below

this.grid1.TableOptions.AllowSelection = Syncfusion.Windows.Forms.Grid.GridSelectionFlags.Row;

Reply
Piruthiviraj Malaimelraj [Syncfusion]
Nov 06, 2017

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

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