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.
Unfortunately, activation email could not send to your email. Please try again.

Changing Cell Background Color

Thread ID:





850 Aug 23,2002 08:35 AM Aug 24,2002 04:30 AM Windows Forms 1
Tags: GridControl
Brian Severa
Asked On August 23, 2002 08:35 AM

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 04:30 AM

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.

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.