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

Cell background color lost when scrolling

2 Answers 326 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dan Kinchen
Top achievements
Rank 1
Dan Kinchen asked on 13 May 2010, 08:09 PM
This seems like a bug, but hopefully someone has run into this before.  I am setting the background color of individual cells based on the data in the underlying object to which the cell is bound.  I'm doing this in the RowLoaded event in the code-behind rather than in XAML.  My code looks like this:

         if ((e.Row is GridViewHeaderRow) || (e.Row is GridViewFooterRow) || (e.Row is GridViewNewRow))  
                return//we want to apply logic to data rows only  
 
            foreach (var cell in e.Row.Cells)  
            {  
                switch (cell.Column.GetValue(NameProperty).ToString())  
                {  
                    case "dcPlanName":  
                        cell.SetBinding(GridViewCell.BackgroundProperty, new Binding("IsNextPlanNameReadOnly") { Converter = new IsTotalRowToColorConverter() });  
                        break;  
                    case "dcLotType":  
                        cell.SetBinding(GridViewCell.BackgroundProperty, new Binding("IsNextLotTypeReadOnly") { Converter = new IsTotalRowToColorConverter() });  
                        break;  
                    case "dcBldgType":  
                        cell.SetBinding(GridViewCell.BackgroundProperty, new Binding("IsNextBuildingReadOnly") { Converter = new IsTotalRowToColorConverter() });  
                        break;  
                    //many more cells...  
                }  
            } 

This works great until I scroll the grid to the right.  There are 30+ columns in the grid so there's a lot of real estate to cover.  Once I scroll to the right and back to the left it starts losing the background colors and they return to the default.  Any simple way around this or do I have to create a custom Style for the cell?  If I have to go the Style route, can someone post the default cell style for the grid.  I seem to remember there's no way to get at it from Blend.

Thanks.

2 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 14 May 2010, 01:09 PM
Hello Dan Kinchen,

The reason for the loss of the background style of the columns is most probably due to the Virtualization of the Columns, which leads to the re-usage of some of them. 
A possible and easy way to correct that is to stop the virtualization in the declaration of the RadGridView:

this.RadGridView1.EnableColumnVirtualization = false;

However, if you have a lot of data, it will lead to slow performance of your Grid.
In order to achieve your purpose you may use StyleSelectors. You can find more information in this blog post.
A good approach in you case may be to use Conditional Formating. I am sending you a sample project where the cells in the second column are coloured depending on their value.

I hope that helps. 


Greetings,
Maya
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.
0
Pavan
Top achievements
Rank 1
answered on 23 Feb 2016, 10:52 AM
Thank you maya  . .
Tags
GridView
Asked by
Dan Kinchen
Top achievements
Rank 1
Answers by
Maya
Telerik team
Pavan
Top achievements
Rank 1
Share this question
or