Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > GridView > Setting radGridView row background color based on the value of a column in the row

Answered Setting radGridView row background color based on the value of a column in the row

Feed from this thread
  • Posted on Jun 17, 2010 (permalink)

    Hi guys,

       I'm a WPF developer, and I'm looking for some sample code that will show me how to set the radGridView row background color based on the value of a column in the row. Do you have an example that will do so?
       Specifically, I want to set a row's background color to Red if the value of Due_Date is within 1 day of today, and to Yellow if it's between 2 and 3 days from today.

    Thanks,

    Les

    Reply

  • Answer Tsvyatko Tsvyatko admin's avatar

    Posted on Jun 18, 2010 (permalink)

    Hi LesPinter,

    I have prepared simple project demonstrating how to achieve the desired functionality using row styles. Please check the attachment and let me know if this works for you.

    If you have any further assistance do not hesitate to contact us.

    All the best,
    Tsvyatko
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
    Attached files

    Reply

  • Posted on Jun 24, 2010 (permalink)

    Hi Tsvyatko,

       Thanks - that's EXACTLY what I needed. You guys are AMAZING!

    Les

    Reply

  • Hicham avatar

    Posted on Dec 18, 2011 (permalink)

    hi,
    please, can anyone tell me how can i do the same for a row in a RadTreeListView??
    thanks.

    Reply

  • Maya Maya admin's avatar

    Posted on Dec 19, 2011 (permalink)

    Hello Hicham,

    You can create a RowStyleSelector. Please take a look at our online documentation and demos for a reference. Although the examples are for RadGridView, exactly the same approach can be used for RadTreeListView as well. 
     

    All the best,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Reply

  • sandy avatar

    Posted on Jan 5, 2012 (permalink)

    hi,
    Any one give solution.
    am using silverlight radgridview for changing row color based on col value.
    same isuue but am using silver light insted of wpf.

    Reply

  • Maya Maya admin's avatar

    Posted on Jan 6, 2012 (permalink)

    Hello Sandy,

    Actually, exactly the same approach is applicable for Silverlight as well. So, you can implement the same idea in your application.  

    Greetings,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Reply

  • Angel avatar

    Posted on Jan 27, 2012 (permalink)

    Hello,

    Is it possible to change only the color of a specific column?

    Thanks!

    Reply

  • Maya Maya admin's avatar

    Posted on Jan 27, 2012 (permalink)

    Hi Les,

    You can use CellStyleSelector - for further information please refer to our online documentation and demos.  

    Kind regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Reply

  • David avatar

    Posted on Feb 7, 2012 (permalink)

    For anyone trying to make this work in silverlight:

    Contrary to Maya's suggestion, this does not actually work in silverlight 4. See references below. The quickest and easiest work around is probably something like the code below. If anyone has better work-around, I would be happy to hear it.

    private void ReportGrid_RowLoaded(object sender, RowLoadedEventArgs e)
    {
        if (e.Row.DataContext is Report)
        {
            e.Row.Background = (e.Row.DataContext as Report).Active ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Colors.Gray);
        }
    }

    http://stackoverflow.com/questions/6526569/silverlight-datagridrow-background-color-change-based-on-a-column-value-and-bind 
    http://stackoverflow.com/questions/4878189/silverlight-how-to-use-a-binding-in-setter-for-a-style-or-an-equivalent-work-a 
    http://forums.silverlight.net/t/130096.aspx 


    Reply

  • Maya Maya admin's avatar

    Posted on Feb 8, 2012 (permalink)

    Hello David,

    Thank you for sharing your insights with the community. Indeed, you can set the background of a row in such a way, but there is still one drawback in this approach. The thing is that RadGridView is virtualized by default, i.e. its visual elements will be recycled and reused on scrolling. That is why it is not recommended to work directly with those elements and their properties (as it is in this case - with rows and their background).
    Working with style selectors will ensure that setting the background relies on bindings and will be evaluated for each row.
    Nevertheless, thank you for you feedback. 

    All the best,
    Maya
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > GridView > Setting radGridView row background color based on the value of a column in the row
Related resources for "Setting radGridView row background color based on the value of a column in the row"

WPF Grid Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]