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

Changing Cell Background Color

Thread ID:





850 Aug 23,2002 12:35 PM UTC Aug 24,2002 08:30 AM UTC WinForms 1
Tags: GridControl
Brian Severa
Asked On August 23, 2002 12:35 PM UTC

Is there a way to change a cell background color in the griddataboundgrid based on data that is bound to it? i.e.: If value-in-cell = "A" then cell background = red If value-in-cell = "B" then cell background = green Thanks in advance Brian

Clay Burch [Syncfusion]
Replied On August 24, 2002 08:30 AM UTC

You can do this in a PrepareViewStyleInfo event which is hit just before the style is used by the drawing code that draws the cell. Changing the style here only affects the visual display, and is not persisted in any manner. So, try adding a handler for this event and use code such as:
Private Sub GridDataBoundGrid2_PrepareViewStyleInfo(ByVal sender As System.Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs) Handles GridDataBoundGrid2.PrepareViewStyleInfo

	If e.Style.Text.StartsWith("A") Then
		e.Style.BackColor = Color.Red
        ElseIf e.Style.Text.StartsWith("B") Then
		e.Style.BackColor = Color.Green
        End If
End Sub


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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