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

Cell color change suddenly

2 Answers 92 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.
Jose
Top achievements
Rank 1
Jose asked on 26 Feb 2012, 06:48 AM
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 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 27 Feb 2012, 07:44 AM
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 >>
0
Jose
Top achievements
Rank 1
answered on 27 Feb 2012, 06:25 PM
Hi,
Thank you for your soon answer and your advice.
I've tried to use the Style Selector and it works perfectly.

Regards,
Jose
Tags
GridView
Asked by
Jose
Top achievements
Rank 1
Answers by
Maya
Telerik team
Jose
Top achievements
Rank 1
Share this question
or