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
300
Bind UltraGrid RowColor value
posted

How to change the UltraGrid RowColor value depending on the bool-typed  value in the Grid?

I want to set RowColor to blue, when data in one my cell is equal True, and Red when False.

For Example:

id  name    fio   isActive

1   test     John    0             ----------this Row must be Red

2  test2    Bill       1            ---------- Blue

I can go through all the lines in UltraGrid and paint them (foreach etc....), but this is not good idea.

 

P.S. Sorry for my English, I'm from Russia.

  • 3707
    posted

    One way you could do this is using the InitializeRow event to set the background color appearance of the row based on the boolean value as each row gets processed into the grid.

    Additionally, if they can later edit the cell's value and you'd need a row background color change you can use the CellChange event.

    private void ultraGrid1_CellChange(object sender, CellEventArgs e)
    {
        if (e.Cell.Column.ToString() == "SomeColumn1")
        {
            if (e.Cell.Text == "False")
                e.Cell.Row.Appearance.BackColor = Color.LightBlue;
            else if (e.Cell.Text == "True")
                e.Cell.Row.Appearance.BackColor = Color.LightPink;
        }
    }

    CellChange event documentation.

    InitializeRow event documentation.