Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
410
FormularCondition Examples
posted
Hi

Are there any examples on how to use FormulaCondition? What I found in the
help is not very useful.

I want to set the color of column based on another column.

I can do this in the InitializeRow-Event, but if there is a great number of
records this is very slow. The second method (which I used right now) is to
use the IUIElementDrawFilter which is very fast, because only the columns
which are visible are processed. But I have to write a lot of code.

I think to use the FormulaCondition is also very fast and is much less code
then the second method I mentioned, but i cannot find a useful examples.

My grid has 3 columns. The grid is filled from a database and I add an
unbound column to show a status. I want to change the backgroundcolor of
this unbound column. The names of the three columns are "ID", "DateIn" and
"DateOut". The name of the grid is dataGrid. I want to set the color to
green if DateIn and DateOut are not DBNull. It should be set to yellow if
only DateOut is DBNull and red if both are DBNull.

Can I use FormularConditions for this? And how to address the columns in the
formula?

Thanks a lot for answering my questions
Michael
Parents
  • 37774
    Verified Answer
    posted

    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 

Reply Children