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

Validate errors with INotifyDataErrorInfo

6 Answers 160 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Daniel Knoll
Top achievements
Rank 1
Daniel Knoll asked on 14 Nov 2011, 03:34 PM
Hi!

How can I validate data asynchronously via the INotifyDataErrorInfo - interface on a RadTreeListView?
Can you please post an example on this?

Thanks in advance,
Marc

6 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 14 Nov 2011, 04:45 PM
Hi David,

I would recommend you to run through this blog post for a reference.
 

Kind regards,
Maya
the Telerik team

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

0
Daniel Knoll
Top achievements
Rank 1
answered on 14 Nov 2011, 08:44 PM
Hi Maya,

thank you for your fast reply! Unfortunately this post uses RIA-Services and a RadGridView. I can't use RIA-services and I have a TreeListView. The row is sent to the service when I press the save-button - not when leaving the cell/row. I guess, in this case I cannot use the RowValidating-event either.

Best regards,
Marc
0
Maya
Telerik team
answered on 15 Nov 2011, 02:34 PM
Hi David Mariacher,

The approach illustrated in the blog post is valid both for RadGridView and RadTreeListView. And the main idea is to benefit from the INotifyDataErorInfo Interface. As mentioned in the post RIA Services Entity object implements it by default, but you still can follow the same approach and implement the interface on your own. 

All the best,
Maya
the Telerik team

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

0
Daniel Knoll
Top achievements
Rank 1
answered on 21 Nov 2011, 02:42 PM
Hi Maya,

I tried to get it to work, but without success...
Please find the attached sample project that consists of a web-part and a silverlight part. It seems like the event for ErrorsChanged is never used by the TreeListView and therefore does not display any validation errors. Do you have any idea what the problem could be?

Best regards,
Marc

Unfortunately, I cannot attach a sample zip-file, so I will open a support ticket!
0
Accepted
Maya
Telerik team
answered on 22 Nov 2011, 01:03 PM
Hi David Mariacher,

I am attaching a sample project illustrating how INotifyDataErorInfo Interface should be implemented correctly. Please take a look at it and follow the suggested approach. 
Nevertheless, based on the sample you sent, I would recommend a couple of things. Firstly, you need to add INotifyDataErrorInfo Interface in the implementation of your business object:

public class ClientCategory : Category, INotifyPropertyChanged, INotifyDataErrorInfo
{
}

Furthermore, once you create a collection and you check whether it is null or not will always return false. So, as it is here:
ObservableCollection<Tuple<string, string>> errors = new ObservableCollection<Tuple<string, string>>();
 
       private ObservableCollection<Tuple<string, string>> GetErrorsSafe()
       {
           if (errors == null)
           {
               errors = new ObservableCollection<Tuple<string, string>>();
               errors.CollectionChanged += errors_CollectionChanged;
           }
 
           return errors;
       }

You will never be subscribed to the CollectionChanged event.  
On other hand why do you add errors in the code-behind? You can try implementing the whole validation logic directly in your business object. What is the exact scenario that you want to accomplish ? 

Greetings,
Maya
the Telerik team

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

0
Daniel Knoll
Top achievements
Rank 1
answered on 23 Nov 2011, 08:48 AM
Hi Maya,

thank you for your example, it really helped me to find the mistakes!
In my business application i was not missing the interface declaration - this was just in the example I sent to you. But it definately helped to check my implementation.The thing I dis not think of was that I had a custom DataTemplate for my cells that did not have any visual elements that could present the errors to the user. I added a border with a flashing red background and bound it to the HasErrors-property with a BooleanToVisibilityConverter and attached a ToolTip at the TextBlock using a binding on the FirstError property - then everything worked fine!
The reason why I can not implement validation on the client (altough it would be much faster) is that our business application is very heavy on the database and if a save operation really succeeds depends on the database. If an error occurs, we will know this and can then add the errors to the ServerErrors-collection-property that is returned by the save-operation via webservice. Then the errors are added via the INotifyDataErrorInfo-interface and everything works as expected!

Greetings,
Marc
Tags
TreeListView
Asked by
Daniel Knoll
Top achievements
Rank 1
Answers by
Maya
Telerik team
Daniel Knoll
Top achievements
Rank 1
Share this question
or