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

[Solved] Maintaing Cell Style when Scrolling

3 Answers 147 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.
Jeff R
Top achievements
Rank 1
Jeff R asked on 28 Jun 2011, 07:45 PM
I am modifying a cell's style using the CellEditEnded event.  It works great except for one issue:  My grid uses horiz and vert scrollbars, and after a cell is edited, and the style is modified for that edited cell - if the grid is scrolled so that the cell begins to move off the viewable area, the cell's new style disappears.  

Appreciate any help!

<Style x:Key="GridViewCellStyle" TargetType="telerik:GridViewCell">
            <Setter Property="Foreground" Value="Red" />
            <Setter Property="Background" Value="Black" />
        </Style>

CODEBEHIND:
private void listGrid_CellEditEnded(object sender, GridViewCellEditEndedEventArgs e) 
            if (e.NewData.ToString() != e.OldData.ToString()) 
            
                GridViewCellBase editedCellBase = (from c in parentRow.Cells where c.Column.UniqueName == e.Cell.Column.UniqueName select c).FirstOrDefault(); 
                GridViewCell editedCell = (GridViewCell)editedCellBase; 
                editedCell.Style = (Style)this.Resources["GridViewCellStyle"];
             }
}

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 29 Jun 2011, 07:17 AM
Hi Jeff Rosen,

The behavior you experience is the expected one since the virtualization of the grid is turned on by default. Consequently, all visual elements are recycled and reused on scrolling and the style you set in this manner is lost. 
The suggested approach is always to work with the data layer, not the UI. You may define a CellStyleSelector
for example and depending on a required condition to set the style you want. Please take a look at our demos and online documentation for a reference on StyleSelectors.
 

Regards,
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
Jeff R
Top achievements
Rank 1
answered on 30 Jun 2011, 07:38 PM
Ok, that was helpful, it got me a bit closer.  I have implemented a CellStyleSelector.  It is still not quite working all the way yet.  When I edit a cell, the style change is not immediately implemented (SelectStyle is not hit upon cell edit).  However, if I scroll the edited cell off the viewable area, then scroll it back into view, the correct style change is then enacted on the edited cell.

I have looked at the CellStyleSelector demo and code, and I see that if you enter a price over $30, it changes the background color immediately.  In looking at the other posts on this subject, it seems that is the expect behavior - that upon cell edit, the CellStyleSelector is hit.  I see that there have been past issues related to this, but were resolved in the Q3 2010 release - but my dlls (trial version) are version 2011.1.419 - so I should be good there. 

Not sure what's going on.... 

0
Jeff R
Top achievements
Rank 1
answered on 30 Jun 2011, 10:24 PM

I was able to add the following line to my CellEditEnded event, which now applies the style immediately after a cell edit:

 

editedCell.Style = editedCell.Column.CellStyleSelector.SelectStyle(parentRow.DataContext, editedCell);


But I am still curious as to why this isn't happening automatically.

Thanks.
Tags
GridView
Asked by
Jeff R
Top achievements
Rank 1
Answers by
Maya
Telerik team
Jeff R
Top achievements
Rank 1
Share this question
or