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

7 posts, 1 answers
  1. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 17 Nov 2011 Link to this post

    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);
            }
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 18 Nov 2011 Link to this post

    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 >>

  3. DevCraft banner
  4. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 18 Nov 2011 Link to this post

    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.
  5. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 18 Nov 2011 Link to this post

    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.
  6. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 29 Nov 2011 Link to this post

    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?
  7. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 30 Nov 2011 Link to this post

    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 >>

  8. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 30 Nov 2011 Link to this post

    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.
Back to Top
DevCraft banner