)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to avoid selection backcolor for particular cells in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: January 12, 2017 |
Last Revised Date: December 23, 2019

Avoid select the backcolor

By default, the SelectionBackColor will override the BackColor of the cell. In order to avoid SelectionBackColor override the BackColor of the cell, the TableControlDrawCellDisplayText event can be used to draw the color on the cell.

C#

//Triggering the event.
this.gridGroupingControl1.TableControlDrawCellDisplayText += new GridTableControlDrawCellDisplayTextEventHandler(gridGroupingControl1_TableControlDrawCellDisplayText);
//Event Customization.
void gridGroupingControl1_TableControlDrawCellDisplayText(object sender, GridTableControlDrawCellDisplayTextEventArgs e)
{
    GridTableCellStyleInfo style = e.Inner.Style as GridTableCellStyleInfo;
    if (style.TableCellIdentity != null && style.TableCellIdentity.Column != null &&
        style.TableCellIdentity.Column.Name == "Description" && e.Inner.RowIndex == 5)
    {
        Rectangle rectangle = e.Inner.ClipBounds;
        rectangle.X -= 1;
        rectangle.Y -= 1;
        rectangle.Height += 3;
        rectangle.Width += 2;
        e.Inner.Graphics.FillRectangle(new SolidBrush(Color.LightBlue), rectangle);
    }
}

 

VB

'Triggering the event.
AddHandler gridGroupingControl1.TableControlDrawCellDisplayText, AddressOf gridGroupingControl1_TableControlDrawCellDisplayText
'Event Customization.
Private Sub gridGroupingControl1_TableControlDrawCellDisplayText(ByVal sender As Object, ByVal e As GridTableControlDrawCellDisplayTextEventArgs)
    Dim style As GridTableCellStyleInfo = TryCast(e.Inner.Style, GridTableCellStyleInfo)
    If style.TableCellIdentity IsNot Nothing AndAlso style.TableCellIdentity.Column IsNot Nothing AndAlso style.TableCellIdentity.Column.Name = "Description" AndAlso e.Inner.RowIndex = 5 Then
        Dim rectangle As Rectangle = e.Inner.ClipBounds
        rectangle.X -= 1
        rectangle.Y -= 1
        rectangle.Height += 3
        rectangle.Width += 2
        e.Inner.Graphics.FillRectangle(New SolidBrush(Color.LightBlue), rectangle)
    End If
End Sub

 

Screenshot

Avoiding selection backcolor for particular cells

 

Samples:

C#: Selection CS

VB: Selection VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

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
Live Chat Icon