Cell forecolor based on another cellvalue

2 posts, 0 answers
  1. pierre-jean
    pierre-jean avatar
    22 posts
    Member since:
    Apr 2011

    Posted 01 Feb 2014 Link to this post

    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
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 03 Feb 2014 Link to this post

    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top