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

how to change row color by cell value?

Thread ID:





19117 Sep 17,2004 03:47 PM UTC Sep 20,2004 05:58 PM UTC WinForms 6
Tags: GridControl
Administrator [Syncfusion]
Asked On September 17, 2004 03:47 PM UTC

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

Administrator [Syncfusion]
Replied On 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; 


Administrator [Syncfusion]
Replied On 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.

Administrator [Syncfusion]
Replied On 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

Administrator [Syncfusion]
Replied On 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

Administrator [Syncfusion]
Replied On 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

Administrator [Syncfusion]
Replied On 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


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