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

how to change row color by cell value?

Hi, I am using a virtual grid with gridcontrol. I want to set the whole row as green when cell value in column 3 equal to 10. What is te best way to do it? Thanks a lot Chris

6 Replies

AD Administrator Syncfusion Team September 17, 2004 07:49 PM UTC

You can use QueryCellInfo to do this. In your event handler, try code like:
if(e.RowIndex > 0 && e.ColIndex > 0)
{

	int val = (e.ColIndex == 3) ? (int)e.Style.CellValue : (int) grid[e.RowIndex, 3].CellValue;
	if(val == 10)
		e.Style.BackColor = Color.Green; 

}


AD Administrator Syncfusion Team September 18, 2004 04:52 AM UTC

In addition to the code above, you probably also need to set gridControl1.Model.Options.RefreshCurrentCellBehavior = GridRefreshCurrentCellBehavior.RefreshRow so the row gets redrawn as the currrentcell moves to make sure the whole row is redrawn. Or, you could subscribe to CurrentCellAcceptedChanges and if the currentcell is in column 3, call grid.RefreshRange on the current row. This woud only redraw the row if the value in column 3 changed.


AD Administrator Syncfusion Team September 20, 2004 01:14 PM UTC

Thanks Clay. It works without implementing your second suggestion. To make this issue more general, is it possible to change the backcolor in one cell based on the value in another cell? For example, when val=10 in col3, I would like the row header colored as yellow when col3 cell color does not change. Thanks Chris


AD Administrator Syncfusion Team September 20, 2004 01:54 PM UTC

Yes, that should fine. BTW - I also suggest taking a look at the PrepareViewStyleInfo event. This is a bit more dynamic than the QueryCellInfo event because its style never gets cached and called more often. Stefan


AD Administrator Syncfusion Team September 20, 2004 04:55 PM UTC

Thanks. The reason that I use QueryCellInfo event is taht i am following the example of Virtual Grid. Do you mean I do not need to plugin querycellinfo event in virtual grid and use PrepareViewStyleInfo for realtime dynamic data in a virtual grid? Thanks >Yes, that should fine. > >BTW - I also suggest taking a look at the PrepareViewStyleInfo event. This is a bit more dynamic than the QueryCellInfo event because its style never gets cached and called more often. > >Stefan


AD Administrator Syncfusion Team September 20, 2004 05:58 PM UTC

Hi Chris, this is kind of a fuzzy answer ... When data are involved that you want to have returned when someone calls Model[rowIndex, colIndex] the nyou must do QueryCellInfo and provide the data there. If however, you just want to supply some view state (e.g. backcolor) and you do not care about having these values be returned when you call Model[rowIndex, colIndex] then PrepareViewStyleInfo might be better since you don''t have to worry about calling ResetVolatileData (clearing the caches) when changes are made. PrepareViewStyleInfo also can take view-specific information into account, e.g. CurrentCell position and has access to fully populated styles that you can access with Model[rowIndex, colIndex]. QueryCellInfo on the other side only knows about the model, not about the view. It''s advantage however is that its values are cached for a short time and therefore is better suited if you want to a bit more complex calculations within the call back method. Stefan

Loader.
Live Chat Icon For mobile
Up arrow icon