DataGridTemplateColumn with row validation

Jul 2, 2009 at 5:10 PM

I'm using a DataGridTemplateColumn with a DatePicker, which works fine until I add a ValidationRule. The process goes like this:

  • CellTemplate is displayed with "1/1/2001"
  • Click to edit the date, change it (via CellEditingTemplate) to "1/1/2009"
  • Click in another column in the same row
  • Original CellTemplate is displayed with "1/1/2001"

At this point, there's no way for me to know that I've actually changed the date until I commit the edit by hitting enter in some other column. This is very unintuitive.

I need the row validation to ensure that some of the other columns aren't empty, so removing it isn't an option.  Is there any way to make the CellTemplate display the uncommitted value?

Thanks,

Jason

Jul 8, 2009 at 1:25 PM
Edited Jul 24, 2009 at 3:14 AM

Anyone else notice this?

Jul 24, 2009 at 3:15 AM

Shameless bump...

Jul 28, 2009 at 6:06 AM

It's a wild guess, but the two things I would check at first is (1) what exactly does your validator function return? (the fact that it works fine until you add the validation rule would seem to suggest a problem there), and (2) does your business object implement INotifyPropertyChanged?

Aug 25, 2009 at 3:20 AM

This happened to me while using row validation. I'm not sure if the setup is exactly the same, but in my case, the business object implements INotifyPropertyChanged and IEditableObject. It appears that the default transactional behavior does not update the business object's properties until the entire row is committed. That is, the Binding.UpdateSourceTrigger defaults to Explicit for template columns, and the source properties for these columns are not updated until the entire row is committed. At this point, the property change notification causes a NullReferenceException because it tries to retrieve the binding target (the DatePicker), but the CellEditingTemplate has already been replaced by the CellTemplate, and the DatePicker no longer exists. The solution is to explicitly set Binding.UpdateSourceTrigger (for any editing controls in a CellEditingTemplate) to LostFocus or PropertyChanged.

Aug 25, 2009 at 1:24 PM
KarlEr wrote:

The solution is to explicitly set Binding.UpdateSourceTrigger (for any editing controls in a CellEditingTemplate) to LostFocus or PropertyChanged.

Perfect, thanks!