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

Cell Background Color

2 Answers 122 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Don
Top achievements
Rank 1
Don asked on 27 Oct 2009, 02:18 PM
I am binding my grid to an object where one of the properties is a color. I would like to set the background of the cell to that color. additionally I would like to allow the user to use a color picker to change the color when the row is in edit mode. What is the best way to go about that. I have tried a couple of things but I can't seem to get the XAML right for a brush or find the right attribute of the cell to put a binding on. Thanks.

Don Miller

2 Answers, 1 is accepted

Sort by
0
Accepted
Pavel Pavlov
Telerik team
answered on 29 Oct 2009, 02:09 PM
Hi Don,

The blogpost here describes some techniques to colorize cells based on a specific value in the underlying business object.

If these approaches are not applicable I would suggest to place a small UserControl inside the cell. This control should take care to read the value from its DataContext and set its own background to the desired color.

To place your user control you will need to set the CellTemplate property of the column to a DataTemplate containing the user control.

In case you need a sample application with this approach or any additional assistance , just let me know.

Best wishes,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Don
Top achievements
Rank 1
answered on 29 Oct 2009, 10:52 PM
I finally realized that the object that the grid is bound to is returned as part of the event arguments. Just casting the object and then setting the cell background works great. Thanks for your help.
Tags
GridView
Asked by
Don
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Don
Top achievements
Rank 1
Share this question
or