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
I would recommend you to run through this blog post for a reference.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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
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.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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!
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 >>
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