Cell color change suddenly

3 posts, 0 answers
  1. Jose
    Jose avatar
    8 posts
    Member since:
    Feb 2012

    Posted 26 Feb 2012 Link to this post

    Hi,
    I have a problem when I'm trying to change the background of a cell.
    I'm using the following statement:

    GridViewItemContainerGenerator container = grid.ItemContainerGenerator;
    GridViewRow actualRow =
    null;
    for
    (int i = row; i <= rowSel; i++)
        actualRow = container.ContainerFromIndex(i)
    as GridViewRow;
        for (int j = col; j <= colSel; j++)
        {
           actualRow.Cells[j].Background =
    new System.Windows.Media.SolidColorBrush((Color)value);
        }
    }
    But when I have more columns than the showed in the grid and I want to see them by moving the scroll bar the color suddenly disappear.
    I notice that the number of RadGridView's cells is less than the real number when I have more columns than the showed in the page.
    I want to know if I'm doing the right way and  How is the best way to achieve this??

    Regards,
    José
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 27 Feb 2012 Link to this post

    Hello Jose,

    Generally, it is not recommended to work with visual elements and their value - as it is in your case - with cells and their background. Since RadGridView is virtualized, those elements will be recycled and reused. The result of this is the behavior you notice in your application as well.
    What I could suggest is to use style selectors instead. 

    Kind regards,
    Maya
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. Jose
    Jose avatar
    8 posts
    Member since:
    Feb 2012

    Posted 27 Feb 2012 Link to this post

    Hi,
    Thank you for your soon answer and your advice.
    I've tried to use the Style Selector and it works perfectly.

    Regards,
    Jose
Back to Top