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

cell style based on cell value with AutoGenerateColumns="True

3 Answers 307 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tomwe
Top achievements
Rank 1
Tomwe asked on 01 Jan 2013, 07:21 PM


Hi
I need to change the background color of a cell based on its value while using AutoGenerateColumns="True
Without using code behind (attach property is acceptable solution) 
The data context is  System.Data.DataTable

 Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 02 Jan 2013, 08:58 AM
Hi,

You will have to define a StyleSelector and assign it for the corresponding column. As your columns are not defined in XAML, but they are auto generated, you will need access the auto generated column when the AutoGeneratingColumn event is fired.  

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Tomwe
Top achievements
Rank 1
answered on 02 Jan 2013, 10:52 AM

Ok,but how do i set the binding in  template to the correct column?

The only solution i can think of is to change the template with code for every column

Thanks in advance

0
Accepted
Dimitrina
Telerik team
answered on 02 Jan 2013, 12:05 PM
Hello,

Actually you do not need to define any template. In order to change the background colour for a cell you will need to define and apply a CellStyleSelector returning a Style targeting GridViewCell.

You can check the Cells WPF Demo and as well this help article about a general information on applying the CellStyleSelector.

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Tomwe
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Tomwe
Top achievements
Rank 1
Share this question
or