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

Triggering on cell value changed

4 Answers 149 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 24 Aug 2011, 03:56 AM
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.


4 Answers, 1 is accepted

Sort by
0
Steven
Top achievements
Rank 1
answered on 24 Aug 2011, 05:30 AM
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?  
0
Nedyalko Nikolov
Telerik team
answered on 29 Aug 2011, 01:31 PM
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 >>

0
Alan
Top achievements
Rank 2
answered on 13 Jan 2012, 06:20 PM
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?
0
Nedyalko Nikolov
Telerik team
answered on 16 Jan 2012, 08:30 AM
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 >>

Tags
GridView
Asked by
Steven
Top achievements
Rank 1
Answers by
Steven
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Alan
Top achievements
Rank 2
Share this question
or