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

Custom Column background

3 Answers 58 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andrew
Top achievements
Rank 1
Andrew asked on 11 Oct 2012, 06:41 PM
I have created a custom column that inherits from GridViewDataColumn and in my CreateCellElement I am trying to bind the cell's background to a color. I use the following code:  


public
override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)

{

    InputChannelInfo channel = dataItem as InputChannelInfo;

 

    TextBlock tb = new TextBlock();

         ...

    Binding colourBinding = new Binding("ChannelColour");

        colourBinding.Source = channel;

        cell.SetBinding(GridViewCell.BackgroundProperty, colourBinding); 

    return tb;

}

This however doesn't work; what happens is that the cell loads but the background remains white. When I use the GridViewCell's Loaded event and do the backgound binding there it will work and the background changes. However I am trying to avoid this way for other reasons. Is there a way to get the cell's background to change when doing the binding in CreateCellElement?


3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 12 Oct 2012, 02:49 PM
Hello,

 Indeed, the initial Background for the Cells cannot be set like so. You could set the Background for the entire column instead.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Andrew
Top achievements
Rank 1
answered on 12 Oct 2012, 02:52 PM
How can you set each cells background separately ?
0
Dimitrina
Telerik team
answered on 15 Oct 2012, 10:19 AM
Hello,

 To set the background per cell, I would suggest you to define a CellStyleSelector for the column.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

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