Michael,
You can reference the columns in the same way that it can be done in the CalcManager (which incidentally you need on the form to use a FormulaCondition). I'm assuming that you're doing this in code with an unbound column, so you could do the following, adding the conditions in the order in which they should be applied:
private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e){ ConditionValueAppearance cva = new ConditionValueAppearance(); FormulaCondition condition = new FormulaCondition(e.Layout.Bands[0].Columns["ID"], "and( [DateIn] != dbnull() , [DateOut] != dbnull() )"); Infragistics.Win.Appearance appearance = new Infragistics.Win.Appearance(); appearance.BackColor = Color.Green; cva.Add(condition, appearance); condition = new FormulaCondition(e.Layout.Bands[0].Columns["ID"], "and( [DateIn] != dbnull() , [DateOut] = dbnull() )"); appearance = new Infragistics.Win.Appearance(); appearance.BackColor = Color.Yellow; cva.Add(condition, appearance); condition = new FormulaCondition(e.Layout.Bands[0].Columns["ID"], "and( [DateIn] = dbnull() , [DateOut] = dbnull() )"); appearance = new Infragistics.Win.Appearance(); appearance.BackColor = Color.Red; cva.Add(condition, appearance); e.Layout.Bands[0].Columns["ID"].ValueBasedAppearance = cva;}
This code works under the assumption that it is the ID column that you want to set the appearances on. You may find it helpful when creating formulas to do it at design-time, even if you don't have the column available there that you want, just so that you can use the designer dialog, which provides a list of the functions and available columns.
-Matt
Hi, I am trying to set some conditional formatting on a column based on the value of another column.
Basically, I want that is a nullable boolean is false, the text in the second column is striked out. When the boolean is NULL, I want the text to be grayed out.
I am using the following code, however, the conditional appearance isn't triggered:
FormulaCondition denyCondition = new FormulaCondition(columnDescription); denyCondition.Formula = "([Column1] = False)"; FormulaCondition emptyCondition = new FormulaCondition(columnDescription); emptyCondition.Formula = "([Column1] = null)";
Appearance denyAppearance = new Appearance(); denyAppearance.FontData.Strikeout = DefaultableBoolean.True; Appearance emptyAppearance = new Appearance(); emptyAppearance.ForeColor = Color.LightGray;
ConditionValueAppearance condValApp = new ConditionValueAppearance();
condValApp.Add(denyCondition, denyAppearance); condValApp.Add(emptyCondition, emptyAppearance);
__grid.DisplayLayout.Bands[0].Columns["Description"].ValueBasedAppearance = condValApp;
What am I doing wrong?
Thx
The syntax for some of your formulas is wrong; the two listed in the code above should actually be "[Column1] = false()" and "isnull([Column1])". What's odd to me is that you say that the appearance isn't triggered, while if I used that syntax, the grid wouldn't fully paint and I'd eventually get an error about the formula not being correct. Does it work if you replace those formulas with what I had listed? Also, is "columnDescription" the same column as '__grid.DisplayLayout.Bands[0].Columns["Description"]'?
"columnDescription" is indeed the same as '__grid.DisplayLayout.Bands[0].Columns["Description"]'
I have changed the formulas but it has no effect.
Even if I use some dummy formula like "1 != 2" the appearance doesn't change.
Using some simple OperatorConditions works fine, however,that's not what i need here...
I'm not sure what the problem could be then, as your code worked for me perfectly (after the formula modifications). I'm also assuming that you have an UltraCalcManager on the form, since a FormulaCondition will not work without it (and may explain why you didn't have the problem that I mentioned regarding the performance and formula compilation errors). If you do have an UltraCalcManager on the form already, you should submit a small sample to Developer Support so that they can look into it.
And UltraCalcManager it was. Never heard of it, never used it before...
Thx!
Does this have to happen on the Initialize Layout event?
Can I set these properties before I bind the data?
Also After adding the UltraCalcManager, how do I associate it w/ the grid?
Thank you.
You shouldn't have to do anything to associate the UltraCalcManager with the grid when you add it to the form at design-time. If you're adding it in code, you can assign the CalcManager property of the grid to the instance of the UltraCalcManager that you've created.
As for setting properties, if the column structure is the same as when you bind the data, you can set the various conditions whenever you want, though generally the ValueBasedAppearance logic makes the most sense at design-time, since otherwise you might be better off using the InitializeRow event (though in the case of FormulaConditions, this may not necessarily be true).