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
close icon

Changing Cell Background Color

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

1 Reply

CB Clay Burch Syncfusion Team 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

Loader.
Live Chat Icon For mobile
Up arrow icon