Cell background color lost when scrolling

3 posts, 0 answers
  1. Dan Kinchen
    Dan Kinchen avatar
    27 posts
    Member since:
    Mar 2010

    Posted 13 May 2010 Link to this post

    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. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 14 May 2010 Link to this post

    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.
  3. DevCraft banner
  4. Pavan
    Pavan avatar
    1 posts
    Member since:
    Feb 2016

    Posted 23 Feb in reply to Maya Link to this post

    Thank you maya  . .
Back to Top