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

How to show cells that were edited in a different color?

6 Answers 38 Views
GridView
This is a migrated thread and some comments may be shown as answers.
danparker276
Top achievements
Rank 2
danparker276 asked on 18 Nov 2011, 03:38 AM
I want the user to see which cells they have edited in a gridview.

I thought if I did this it would work, but it doesn't

        private void rgv_CellEditEnded(object sender, Telerik.Windows.Controls.GridViewCellEditEndedEventArgs e)
        {
            e.Cell.Foreground = new SolidColorBrush(Colors.Yellow);
        }

6 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 18 Nov 2011, 08:47 AM
Hello Dan,

You can try to expose properties in your business object specifying whether it has been edited or not. Afterwards, you can define a CellStyleSelector and based on the values of those properties to change the foreground. I am attaching a sample project illustrating the suggested approach.
Please take a look at it and let me know whether it meets your requirements.

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
danparker276
Top achievements
Rank 2
answered on 18 Nov 2011, 06:59 PM
Thanks, that's the functionality that I'm looking for.  There's no way to do this on the cellEdited ended or some other event though?  I'd rather not add all that extra coding to my class definition that I pass back and forth to my web service.  It's also about 8 columns I have to do.  This will work fine, but I'm just wondering if there is a way with less coding.  There might be other grids I have to do this for too.
0
danparker276
Top achievements
Rank 2
answered on 18 Nov 2011, 07:31 PM
Actually, if I just use _CellEditEnded event and do:
  e.Cell.Background = new SolidColorBrush(Colors.Yellow);


It works for background but not for foreground.  I'd probably just do it this way, even if it's only the background I can change.

Edit:  It works for my combo box, but not for my decimal value.
0
danparker276
Top achievements
Rank 2
answered on 30 Nov 2011, 01:10 AM
private void rgv_CellEditEnded(object sender, GridViewCellEditEndedEventArgs e)
{
     
    GridViewCell cell = e.Cell;
    if (e.OldData != e.NewData)
    {
        cell.Foreground = new SolidColorBrush(Colors.Blue);
    }
 
}
If I do the above on cell edit ended, this will work.  Now I have to take care of the new rows.

On the AddingNewDataItem event, I set something in the object saying it's a new row.  Then I use CellStyleSelector on the columns.
This seems to be working without having to change my object much.

I couldn't find a way to change the color of a new row without using the cellStyleSelector though.  Is there an event I could use the change the foreground in those rows?
0
Accepted
Maya
Telerik team
answered on 30 Nov 2011, 10:41 AM
Hi Dan,

Actually, it is not recommended to work with the visual elements and their properties - as it is in this case with cells and their background/foreground properties. As the virtualization of RadGridView is turned on by default, those visual elements will be recycled and reused on scrolling. That is why I would suggest you to implement the logic with CellStyleSelector.

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
danparker276
Top achievements
Rank 2
answered on 30 Nov 2011, 06:30 PM
Thanks, that makes sense.  I wasn't thinking about virtualization.  My tables for this purpose are only going to be 1-8 rows, so I'll turn virtualization off.
Tags
GridView
Asked by
danparker276
Top achievements
Rank 2
Answers by
Maya
Telerik team
danparker276
Top achievements
Rank 2
Share this question
or