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

[Solved] How to colorize cell

1 Answer 120 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.
Konrad Sikorski
Top achievements
Rank 1
Konrad Sikorski asked on 30 Jun 2011, 02:18 PM
Hi,

I have a custom column and I would like to set a background color. I know that I can use StyleSelector and it works fine but I want to close this logic in column definition. I was trying to set cell.Background in CreateCellElement method but with no effects:
public class ColorColumn : GridViewDataColumn
    {
        public override FrameworkElement CreateCellElement( GridViewCell cell, object dataItem )
        {
            cell.Background = CalculateCellColor( dataItem );
  
            return new TextBlock { Text = CalculateCellValue( dataItem ) };
        }
    }

So now I am doing this like this:
public class ColorColumn : GridViewDataColumn
    {
        public ColorColumn()
        {
            this.CellStyleSelector = new ColorColumnStyleSelector();
        }
  
        public override FrameworkElement CreateCellElement( GridViewCell cell, object dataItem )
        {
            return new TextBlock { Text = CalculateCellValue( dataItem ) };
        }
  
        private class ColorColumnStyleSelector : StyleSelector
        {
             ...
        }
    }

1. Why cell.Backround = ... doesn't work
2. Do you know other solution

1 Answer, 1 is accepted

Sort by
0
Yordanka
Telerik team
answered on 05 Jul 2011, 07:32 AM
Hello Konrad Sikorski,

Please, try our latest internal build - version .0704 where the issue is fixed.

Let us know in case of any problems.

Best wishes,
Yordanka
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
Tags
GridView
Asked by
Konrad Sikorski
Top achievements
Rank 1
Answers by
Yordanka
Telerik team
Share this question
or