Triggering on cell value changed

5 posts, 0 answers
  1. Steven
    Steven avatar
    84 posts
    Member since:
    Oct 2010

    Posted 23 Aug 2011 Link to this post

    I have a gridview that I want to color each cell that the user has changed, as well as set an indicator on the bound data value that it has been updated.   Since there appears to be no MVVM way of doing PropertyTriggers at this point, I found what appears to be the closest event to what I need.   CellValidating.

    With this, I have several problems:

    1)    In this event, I can seem to get to the OldValue and NewValue properties, except when using a RadDatePicker (and possibly other controls) in a CellEditTemplate.   The NewValue always seems to be null, which indicates there is an event sequence issue here.  I would expect this event to fire AFTER the DatePicker updates so that the NewValue reflects what the user selected/entered, not before, as it appears to be. 

    2)    Because the e.Cell.OldValue and e.Cell.NewValue properties return objects (and they are indeed different instances of those objects), I cannot easily compare them accurately, especially when dealing with dates and floating points.  Using ToString() is not good enough and trapping for every possible object and container type can be laborious and error prone.

    So, with that....

    1)    Am I using the right event (or method) to capture a changed cell value event?
    2)    How can I best compare the old and new values to determine if the content has actually changed, rather than just instances of the objects.


  2. Steven
    Steven avatar
    84 posts
    Member since:
    Oct 2010

    Posted 24 Aug 2011 Link to this post

    Update:

    After some playing around, I found that if I capture the old value during the PreparingCellEdit and store it and then recapture the cell value during CellEditEnded or CellValidated, I can accurately compare the old and new values.

    However, if the user holds down the tab key, the events don't fire in a predictable pattern and I get cell value changes detected when there were none.

    So, I am back to square one:

    How do I determine when a cell value has actually changed when an edit template is used or not?  
  3. DevCraft banner
  4. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 29 Aug 2011 Link to this post

    Hi Steven,

    I think that CellEditEnded event is the best way to achieve such behavior. You can compare the old and new data with a code similar to the following:

    object.Equals(e.OldData, e.NewData)

    Let me know if this doesn't help.

    Best wishes,
    Nedyalko Nikolov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  5. Alan
    Alan avatar
    32 posts
    Member since:
    Jan 2011

    Posted 13 Jan 2012 Link to this post

    Has this broke on WPF Q3 2011?

    On my radgridview both e.OldValue and e.NewValue are coming back null (C#) despite having a prior and new entries made into the grid?
  6. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 16 Jan 2012 Link to this post

    Hi,

    Could you send me a sample project which I can debug on my side in order to see what is going on?
    Thank you in advance.

    Kind regards,
    Nedyalko Nikolov
    the Telerik team

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

Back to Top
DevCraft banner