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

Cell colour disappears when scrolling/resizing

4 Answers 164 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kristjan Einarsson
Top achievements
Rank 1
Kristjan Einarsson asked on 11 Feb 2011, 10:10 AM
Hi,
I'm changing the cell colour in the RowLoaded event via:
int reservedCells = 5;
if (item.Values[i].OriginalValueChanged)
{
         e.Row.Cells[i + reservedCells].Background = new SolidColorBrush(Color.FromRgb(255, 0, 0));
}

And it works fine until I scroll the grid or just re-size the window, is this a bug or am I doing the completely wrong ?

cheers
kristján.

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 11 Feb 2011, 10:19 AM
Hello,

 RowLoaded is not the right place to style cells due to horizontal virtualization. Please use CellStyleSelector - you can check our demos for more info.

Kind regards,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Kristjan Einarsson
Top achievements
Rank 1
answered on 11 Feb 2011, 10:38 AM
Hi, thanks I'll take a closer look to the demo but I'm doing all of the binding in codebehind, haven't found any good examples

cheers :)
0
Kristjan Einarsson
Top achievements
Rank 1
answered on 11 Feb 2011, 03:43 PM
do you have any examples where you do this in code behind that you can point to, I'm using dynamic columns for the grid and I have not found any.

Best regards
Kristján.
0
Accepted
Maya
Telerik team
answered on 11 Feb 2011, 04:06 PM
Hello Kristjan Einarsson,

Once you define the styles in the Resources section:

<Window.Resources>
   <my:NumberStyle x:Key="numberStyle">
     <my:NumberStyle.BigNumberStyle>
       <Style TargetType="telerik:GridViewCell">
          <Setter Property="Background" Value="HotPink"/>
          <Setter Property="Foreground" Value="White" />                 
        </Style>
      </my:NumberStyle.BigNumberStyle>
      <my:NumberStyle.SmallNumberStyle>
         <Style TargetType="telerik:GridViewCell">
           <Setter Property="Background" Value="Yellow" />
           <Setter Property="Foreground" Value="Black" />
          </Style>
      </my:NumberStyle.SmallNumberStyle>
</my:NumberStyle>      
</Window.Resources>

You may set the CellStyleSelector for a column like follows:
this.playersGrid.Columns[1].CellStyleSelector = (StyleSelector)this.Resources["numberStyle"];

 

Regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
Kristjan Einarsson
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Kristjan Einarsson
Top achievements
Rank 1
Maya
Telerik team
Share this question
or