This is a migrated thread and some comments may be shown as answers.

Cell forecolor based on another cellvalue

1 Answer 80 Views
ListView
This is a migrated thread and some comments may be shown as answers.
pierre-jean
Top achievements
Rank 1
Veteran
Iron
pierre-jean asked on 01 Feb 2014, 03:56 PM
Hello
In a listview that I populate "manually" I whish to change the font Color of a cell text based on the value of another cell (in the same "line"),
In the cell formatting event I do not see how to access to the value of another cell ? or should I use another event ?

Thanks in advance

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 03 Feb 2014, 12:29 PM
Hi Pierre-jean,

Thank you for writing. 

You can access the row from by casting the CellElement to DetailListViewDataCellElement and using its Row property. Here is an example where I am checking the value of the "ID" column:
void radListView1_CellFormatting(object sender, ListViewCellFormattingEventArgs e)
{
    if (e.CellElement is DetailListViewDataCellElement)
    {
        DetailListViewDataCellElement dataCell = (DetailListViewDataCellElement)e.CellElement;
        if ((int)dataCell.Row["ID"] % 2 == 0)
        {
            e.CellElement.BackColor = Color.Red;
        }
        else
        {
            e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
        }
    }
}

I hope this helps. 

Regards,
Stefan
Telerik
TRY TELERIK'S NEWEST PRODUCT - APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
ListView
Asked by
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Answers by
Stefan
Telerik team
Share this question
or