Change the background of rows that matches a condition

2 posts, 0 answers
  1. Danilo
    Danilo avatar
    1 posts
    Member since:
    Feb 2016

    Posted 25 Feb Link to this post

    Hello! I've been trying to highlight some rows in my grid that that indicates the start of a group of elements.
    Problem is, when i use the RowLoaded event, it works right, changing the row i need but also changing other rows of the grid, that doesn't match the condition.

    I want to change the background color in the rows where a string property is null or empty.

    Is there any better way to approach it?

    private void GridPer_RowLoaded(object sender, RowLoadedEventArgs e)
            {
                if (e.DataElement != null && string.IsNullOrEmpty(((e.DataElement as ClassifPeriods).Classificacao.CodMae)))
                    e.Row.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#CC0000"));
            }

  2. Yoan
    Admin
    Yoan avatar
    1066 posts

    Posted 26 Feb Link to this post

    Hello Danilo,

    The recommended approach is to use a RowStyleSelector as demonstrated in this help article.

    Regards,
    Yoan
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top