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.
Syncfusion Feedback

Individual cell style setting

Thread ID:

Created:

Updated:

Platform:

Replies:

920 Sep 3,2002 05:32 PM UTC Sep 5,2002 06:29 AM UTC Windows Forms 7
loading
Tags: GridControl
Andre King
Asked On September 3, 2002 05:32 PM UTC

Hi, I am evaluating the Essential Grid. I am trying to set the format of a cell based on the value contained within the cell. The PrepareViewStyleInfo event works well for this; unfortunately, the code I am running to evaluate the condition is quite slow and as a consequence, the grid cursor movements are slow. For our application, the style of the cells only needs to be re-evaluted when new data is loaded and so I would like to set the style only at that time (I guess it would also be necessary to evaluate on column moves, sorting etc). Is this possible, or can you suggest a better method? The code looks something like: private void grid1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e) { double rejectMax = getRejectMax(); // this takes too long for smooth cursor movement double rejectMin = getRejectMin(); double val = (double)e.Style.CellValue; if ( val < rejectMin) e.Style.BackColor = Color.Red; else if (val > rejectMax) e.Style.BackColor = Color.Yellow; } }

Clay Burch [Syncfusion]
Replied On September 3, 2002 05:48 PM UTC

> Hi, I am evaluating the Essential Grid. I am trying to set the format of a cell based on the value contained within the cell. The PrepareViewStyleInfo event works well for this; unfortunately, the code I am running to evaluate the condition is quite slow and as a consequence, the grid cursor movements are slow. > For our application, the style of the cells only needs to be re-evaluted when new data is loaded and so I would like to set the style only at that time (I guess it would also be necessary to evaluate on column moves, sorting etc). Is this possible, or can you suggest a better method? > The code looks something like: > private void grid1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e) > { > double rejectMax = getRejectMax(); // this takes too long for smooth cursor movement > double rejectMin = getRejectMin(); > double val = (double)e.Style.CellValue; > if ( val < rejectMin) > e.Style.BackColor = Color.Red; > else if (val > rejectMax) > e.Style.BackColor = Color.Yellow; > } > } > Before trying to respond, can you provide some more information? Are you using a GridControl or a GridDataBoundGrid? If it is a GridControl, are you populating the grid with this data, or are you using the grid in a virtual manner, handling QueryCellInfo? I suspect that if getRjectMin takes a long time, you will want to actually populate a GridControl with your data (& backcolor), and then only call getRejectMin when the data changes, not everytime it is displayed.

Andre King
Replied On September 3, 2002 06:39 PM UTC

Hi, Thanks for the quick reply. Sorry, I forgot to say I am using the databoundgrid and am setting the datasource to a datatable to populate the grid. Thanks.

Clay Burch [Syncfusion]
Replied On September 4, 2002 06:23 AM UTC

For a GridDataBoundGrid, there is no individual cell information store by the control. This is why events like PrepareViewStyleInfo (or QueryCellInfo) are used to provide the data on demand. So, in a GridDataBoundGrid, the only way to color a cell is through an event. In this case, you would have to either speed up the processing in the getRejectMax and getRejectMin methods, or maybe somehow store these values and just retrieve them in your event handler instead of calculating them. If the values from GetRejectMax and getRejectMin are not so volatile that they have to be computed at the instance of a cell being displayed, then precomputing them may be an option. If they have to be computed at the instance of display, then speeding up how they are computed is the only answer.

Andre King
Replied On September 4, 2002 11:41 AM UTC

Thanks for your reply. I'll probably end up caching the values as you suggest.

Clay Burch [Syncfusion]
Replied On September 4, 2002 04:33 PM UTC

Just something to try... I don't think it will make a noticeable difference. Move your code from PrepareViewStyleInfo into QueryCellInfo. QueryCellInfo is hit only once per draw (and its values cached temporarily) whereas PrepareViewStyleInfo may be hit more often as it does not cache anything.

Andre King
Replied On September 4, 2002 09:58 PM UTC

Thanks for the suggestion. I moved the code to the QueryCellInfo event but got some strange behaviour. One thing that is different is the method I was using to get the header: grid[0,e.ColIndex].CellValue (is this the best way to get the header text?) gives me an empty string now. The coloring of the cells is erratic and changes as I move around in the grid. The speed does seem a bit better, but I think I will try optimizing the lookup and use the other method.

Clay Burch [Syncfusion]
Replied On September 5, 2002 06:29 AM UTC

Normally, that would be the correct way to get the header text. But in QueryCellInfo, you have to be careful as trying to access the values from other grid cells result in another call to QueryCellInfo. Without taking care, you can set up recursive calls that result in infinite loops or other problems.

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

;