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
16 Answers, 1 is accepted
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
Thanks - that's EXACTLY what I needed. You guys are AMAZING!
Les
please, can anyone tell me how can i do the same for a row in a RadTreeListView??
thanks.
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.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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.
Actually, exactly the same approach is applicable for Silverlight as well. So, you can implement the same idea in your application.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Is it possible to change only the color of a specific column?
Thanks!
You can use CellStyleSelector - for further information please refer to our online documentation and demos.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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.
{
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
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.
Maya
the Telerik team
That is, in the example, the Due_Date property on the object is used for this value. What if you don't have a fixed property because they are dynamic and are loaded at runtime with calls to GridViewDataColumn.
You can try working with RowStyleSelector. Check out this article and this demo for a reference.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
I had been using a RowStyleSelector but not using it correctly. The demo you pointed me to showed what I was doing wrong. Thank you so much!
An example would be if cell1 - cell2< 0 then color.Red.
Thank you in advance
You can work with two properties values simultaneously. As it is in the case from the documentation - instead of checking only the value of StadiumCapacity, you can verify 'Name' property and only after that - return the style you want.
Maya
Telerik
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 >>
That worked perfectly.
Thank you