Articles in this section
Category / Section

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

2 mins read

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 in WinForms GridGroupingControl, 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 in WinForms GridGroupingControl

 

Samples:

C#: Selection CS

VB: Selection VB

Conclusion

I hope you enjoyed learning about how to avoid selection backcolor for particular cells in WinForms GridGroupingControl.

You can refer to our WinForms GridGroupingControl’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridGroupingControl documentation to understand how to present and manipulate data. 

For current customers, you can check out our WinForms from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms GridGroupingControl and other WinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied