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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Conditionally setting Backcolor of cells

Thread ID:

Created:

Updated:

Platform:

Replies:

11140 Feb 24,2004 06:42 PM UTC Feb 24,2004 09:31 PM UTC WinForms 1
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On February 24, 2004 06:42 PM UTC

I would like to conditionally set the background color of a cell in a databound datagrid based on the value of the current cell compared to the cell 2 places before it. For example, the data in the row to be compared is: Forecast: 1 Actual: 2 When I use the following code, the grid is all white until i click somewhere on the grid, and eventually it errors out. Private Sub mysched_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs) Handles mySched.PrepareViewStyleInfo If e.RowIndex = 1 And e.Style.CellValue.ToString.StartsWith("A") Then If CInt(mySched.Model(1, e.RowIndex - 2).CellValue.ToString.Substring(10)) < CInt(e.Style.CellValue.ToString.Substring(8)) Then e.Style.BackColor = Color.green End If end sub I tried using the QueryCellInfo event, but that didn''t work so well either. If there are any suggestions I''d greatly appreciate it. Thanks Ryan

Administrator [Syncfusion]
Replied On February 24, 2004 09:31 PM UTC

PrepareViewStyleInfo is the place you need to do this. I think you have to be more careful with teh indexes. If you want to reference 2 coluns prior, then the current column must be greater than 2 for this to make sense. Here is a try at this using aribitray rows > 0.
Private Sub mysched_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As GridPrepareViewStyleInfoEventArgs) Handles mySched.PrepareViewStyleInfo
	If e.RowIndex > 0  And e.ColIndex > 2 Then
		if( e.Style.CellValue.ToString.StartsWith("A") Then
			If CInt(mySched.Model(e.RowIndex, e.ColIndex - 2).CellValue.ToString.Substring(10)) < CInt(e.Style.CellValue.ToString.Substring(8)) Then
				e.Style.BackColor = Color.green
			End If
		End If
	End If
end sub

CONFIRMATION

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.

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

;