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

Can not leave cell with validationerror

3 Answers 253 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Stefan
Top achievements
Rank 1
Stefan asked on 26 Oct 2011, 01:24 PM
Hello!

We want to implement validation in the Wpf RadGridView in such a way that the user can leave a cell that contains an error,
the cell should still display the invalid input, and still display the red error-border.
This is the normal behaviour for ordinary Wpf-controls, but a Grid cell seems to force the user to correct the input before she can continue.

regards
Stefan Wimo

3 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 26 Oct 2011, 03:04 PM
Hello Stefan,

All you have to do is to validate your object via IDataErrorInfo or INotifyDataErrorInfo interfaces (if IDataErrorInfo is used your business object should implement INotifyPropertyChanged interface) and set RadGridView.ValidatesOnDataErrors property to "InViewMode".
Let me know if this doesn't help.

Regards,
Nedyalko Nikolov
the Telerik team

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

0
Stefan
Top achievements
Rank 1
answered on 27 Oct 2011, 08:00 AM
Hello!

Ah, I didn't know about INotifyDataErrorInfo. This solution works great when the VM-property is of string type.
When the property is of some other type that doesn't fit in the string,
this method will fail too I'm afraid, since I'm validating the VM-property
itself and not the current UI-input...
I want the user to be able to enter "123abc" into a field that is bound to an integer property, and
having the validation performed before the property is changed. Isn't that what validation is all about?
I could solve it with something like this:

class Person : INotifyDataErrorInfo
{
    string Name {get;set;}
    int Age {get;set;}
    string AgeInput
    {
        get { return this.Age.ToString();}
        set
        {
            if (IsValidAge(value))
            {
                this.Age = int.Parse(value);
            }
        }
    }
    
    public IEnumerable GetErrors(string propertyName)
    {
        ...
        if (propertyName == "AgeInput")
        {
            // Validate using IsValidAge method!
        }
        ...
    }
}
   
But that seems to create a lot of overhead...

regards
Stefan Wimo
0
Nedyalko Nikolov
Telerik team
answered on 31 Oct 2011, 11:16 PM
Hello Stefan,

Generally these interfaces are designed to provide business logic validation, but such asynchronous validation cannot be done without saving the "wrong" value into the underlying property. This cannot be done with the .NET framework (there is no way to store string which cannot be parsed to a number into an integer field (property)). The only way to validate such value with RadGridView is to handle RadGridView.RowValidating event which is fired just before actual save of the "new" value, unfortunately user will have to correct the value in order to exit edit mode.

Let me know if there is something unclear.

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
Stefan
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Stefan
Top achievements
Rank 1
Share this question
or