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

IDataErrorInfo.Error is ignored

6 Answers 305 Views
GridView
This is a migrated thread and some comments may be shown as answers.
sprucely
Top achievements
Rank 1
sprucely asked on 04 Oct 2011, 08:34 PM
When I enter an invalid value for a property and attempt to move focus, RadGridView functions as expected. It accesses IDataErrorInfo.Item[propertyName] and holds focus until I enter a valid value or cancel the edit. I would expect it to behave in a similar manner with regard to IDataErrorInfo.Error and row edits. But it doesn't. It never accesses IDataErrorInfo.Error when row edits end. When I create a new row, it only validates the properties as I change them. So any invalid properties that I have not touched remain invalid, and the row edit is accepted.

How can I make it validate all columns and/or the entire entity when a row edit ends? I can't use your implementation of INotifyDataErrorInfo because the projects containing entities don't reference Telerik libraries. Do I have to manually handle the RowValidating event?

Some of the other interfaces my entity implements include...
  • INotifyDataErrorInfo (local implementation to be replaced when .Net 4.5 is released)
  • IRevertibleChangeTracking
  • IEditableObject

6 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 07 Oct 2011, 02:03 PM
Hi Sprucely,

Indeed RadGridView will check only changed items when validation is done by IDataErrorInfo interface. This interface lacks notification part like (INotifyDataErrorInfo) and therefore RadGridView depends on INotifyPropertyChanged interface for the notification part.

You can use Telerik.Windows.Data.INotifyDataErrorInfo interface, which could be used instead MS.INDEI interface. Keep in mind that with .NET 4.5 you will have to recompile your code to use MS.INDEI, since we will remove our copy. We added this interface just because we use common code base for WPF and Silverlight (SL4 introduces this interface).

RadGridView also supports IEditableObject interface, so this interface also could be used to achieve your goals.

Let me know if there is something unclear.

Best wishes,
Nedyalko Nikolov
the Telerik team

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

0
Brian
Top achievements
Rank 1
answered on 28 Jun 2012, 04:22 PM
I have the same problem, but it is completely unrelated to INDEI. I want to be able to show row level errors only, not cell level errors. If I have a validation error that says that the combination of multiple properties on a row in combination with the combination of multiple properties on another row causes a validation error, I would like to be able to just give a row level error indication - as in the whole object is in error, not specific properties. 

Windows Forms did this with the IDEI interface by consulting the IDEI.Error property for displaying row level errors, and used the IDEI indexer for the cell level errors. 

Is there any way to achieve the same thing (row level validation indications only) with radGridView?
Thanks,
Brian
0
sprucely
Top achievements
Rank 1
answered on 28 Jun 2012, 04:47 PM
I ended up listening to GridViewRowValidatingEvent and manually filling up the the ValidationResults collection with any errors found. IIRC leaving the PropertyName blank indicates a row-level error. Be aware that if a row validation involves comparisons to other rows, it can significantly impact performance if you have many rows.
0
Brian
Top achievements
Rank 1
answered on 28 Jun 2012, 10:36 PM
Thanks much. Ran into that approach in the docs shortly after posting. Now trying to solve two other problems: that only seems to work if you edit a field, not for initial load if you have invalid data. So need to get the same thing to happen on initial read of the data as well, as it would work with IDEI. The other is that we need to allow the user to edit other rows even when the current row is indicating an error. The default behavior of the grid keeps you focused on the current row until you fix the problem.

If anyone has any hints on how to address these, would greatly appreciate.
0
sprucely
Top achievements
Rank 1
answered on 29 Jun 2012, 03:40 PM
You might try triggering a property change event (without actually changing any property). I think that causes the DataGrid (and DataBindings in general) to check for validation errors. If it only checks for a specified property, try passing String.Empty in the PropertyName parameter. I think that indicates entity/row-level validation. I'm not sure about disabling focus capture for a row in edit mode.
0
Brian
Top achievements
Rank 1
answered on 29 Jun 2012, 03:50 PM
Unfortunately the RowValidating event does not appear to fire when the binding does a get, which is when validation normally runs for IDEI. I can force a refresh of the bindings with a PropertyChanged event for the main collection like you said, but it does not raise the event. Only on editing a cell in a row does it fire the event.
Tags
GridView
Asked by
sprucely
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Brian
Top achievements
Rank 1
sprucely
Top achievements
Rank 1
Share this question
or