Hi,
I'm using v9.1
So I'm trying to keep some conditional formatting intact in an ultragrid for a particular column when a row is selected (and subsequently highlighted). I'm using the BeforeSelectChange event to reset the individual cell selectedappearances to what I want them to be. I was easily able to translate the formatting code we have for everything EXCEPT the conditional formatting. Normally we set a property on the UltraGridColumn (ValueBasedAppearance taking a ConditionalValueAppearance that we create with a FormulaCondition). The problem is that there is no such ValueBasedAppearance property on the cell (which is what I have control over in BeforeSelectChange). I need to somehow tinker with the cell's selectedappearance and only that one cell's selectedappearance on row select. Any ideas how I can do this? I've to the length of even trying to evaluate the formulacondition myself and basing the formatting off of that result....but I haven't achieved that yet, and it even seems like an unnecessary step in the first place. Any ideas for how I can keep the conditional formatting intact for a selected row?
Thanks!
You are correct - there is no corresponding Selected property for ValueBasedAppearances.
So there are a couple of ways you can achieve what you want:
1) Don't use a ValueBasedAppearance. Instead, use the InitializeRow event to examine the cell's vaue and set it's Appearance and also it's SelectedAppearance.
2) Use a DrawFilter to change the appearance properties of the cell when it is selected.
I'd like to go with option #1, but it's a little unclear to me how/where the formula would be evaluated. I have is a FormulaCondition object (which I previously just handed to a ConditionValueAppearance along with the intended appearance). It sounds like from "examine the cell's value", you mean inspect the cell's value via GetCellText or something like that....when in fact what I really need to do is get just a boolean result from the FormulaCondition based off the cell's value. Is there something you had in mind to do this?
When I said "examine the cell's value", I was thinking about using GetCellValue or GetCellText and then evaluated the condition in code.
Using a formula will be a little trickier, but it can be done. What you would have to do is add an unbound column to the grid and set it's DataType to boolean and apply your formula to that column. The formula will have to be modified slightly because you will need to use the name of the actual column that contains the data.
This column need not be visible to the user - you can set it's Hidden property to true.
Then inside InitializeRow, you examine the value of the unbound column and cast it to a bool and use that bool to determine the appearance of the cell.
I think this will work - but there might be a slight complication because the calculations are performed asynchronously or because of the grid's optimizations to calculate visible objects first. I think it will work, because visibility optimizations are row-based. So even if the column is hidden, it should be calculated as long as the row is in view, and that's all that matters here. But you might have to check for null or a calculation error when you get the value of the unbound cell.
Hi Mike,
That's a very interesting and creative approach, but is there any way to avoid having to add an extra hidden column? Perhaps I could just evaluate the formula myself? Since I have access to all of the cells in that row at the time of InitializeRow (or BeforeSelectChange as well), perhaps there could be a way to evaluate that particular FormulaCondition. Is this not the case?
It is possible to evaluate a single formula. The UltraCalcManager component has a Calculate method.
You can pass in a formula and get a result. But, I'm not sure it's a good way to go.
The Calculate method has to add the formula into the calculation network and then wait for the CalcManager to process it in the normal course of calculation processing. So if there are other calculations going on in your application, you might not get an immediately response. This is probably a good thing, though, since if your formula relies on any other calculations for it's values, it will force those to be calculated first.