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.

how to change row color by cell value?

Thread ID:

Created:

Updated:

Platform:

Replies:

19117 Sep 17,2004 11:47 AM Sep 20,2004 01:58 PM Windows Forms 6
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On September 17, 2004 11:47 AM

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 03:49 PM

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 12:52 AM

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 09:14 AM

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 09:54 AM

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 12:55 PM

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 01:58 PM

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

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.

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.

;