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

Custom Validation results in GridView do not show up in Validation Summary

3 Answers 290 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paul Brause
Top achievements
Rank 1
Paul Brause asked on 07 Feb 2011, 05:52 PM

Hi,

I am working on a silverlight page that contains a GridView. The Gridview is populated via a RadDomainDataSource. On the same page I have a validation summary control. When the user enters wrong data into a cell, e.g. types some text into an integer field, the grid marks the erroneous cell in red,displays the error message next to the erroneous cell and adds the error message to the validation summary.
You can see the output in the image firstimage.jpg.
The following code shows the binding of the mentioned cell (GridviewColumn):

<Controls2:ctlGridViewColumn 
    UniqueName="Masterprice" 
    DataMemberBinding="{Binding Masterprice, Converter={StaticResource decimalConverter}, Mode=TwoWay,   
    NotifyOnValidationError=true, ValidatesOnExceptions=True}" TextAlignment="Right"/>


When the user triggers errors in the grid cells which are generated via custom validation via RIA Services the grid behaves differently.
It marks the whole row red and displays a red exclamation mark at the beginning of the row containing the erroneous cell.
It does not show the error text in a red box like in the first image, you have to move the mouse cursor over the erroneous cell to get a tooltip describing the error.
The ugly thing is that the error message is not added to the validation summary at the bottom of the page so that is not visible.
This behavior is demonstrated in the image secondimage.jpg.

Here is the XAML code for this GridviewColumn:

<Controls2:ctlGridViewColumn 
    DataMemberBinding="{Binding PLU, Mode=TwoWay, NotifyOnValidationError=True
    ValidatesOnExceptions=True}"/>

Any ideas what I am doing wrong, here?

Janni

3 Answers, 1 is accepted

Sort by
0
Paul Brause
Top achievements
Rank 1
answered on 08 Feb 2011, 10:54 AM

Shame on me, it was not a bug in the RadGridView, but me :-)

Here is my custom validator class:

public class ArticleValidator
{
public static ValidationResult IsFollowPluValid(string text, ValidationContext context)
{
   int followPlu = Int32.Parse(text); 
   bool valid = (followPlu >= 0) && (followPlu <= 9999); 
   if (valid == false) 
       return new ValidationResult("Fehlerhafte FollowPLU, blabla!"); 
   else return ValidationResult.Success; 
}
}

The problem lies in the way I am creating the ValidationResult in case that the property followPlu is not in the range from 0 to 9999.

I did not add the name of the erroneous property to the validation result constructor so that the RadGridView does not know which property is affected and thus cannot show the red rectangle on the correct column! The ValidationSummary also needs the name of the affected property otherwise it does not show up the error.

Here is how the correct code should be:

return new ValidationResult("Fehlerhafte FollowPLU, blablabla", new string [] {"FollowPLU"});

I added a string array containing the name of the erroneous property (you can provide more than one property!) and the GridView works as expected :-)

0
Louis Bouchard
Top achievements
Rank 1
answered on 24 Feb 2011, 04:27 AM
I have the same error (except I use GridViewDataColumn in RadGridView) but I don't see the problem.

<telerik:GridViewDataColumn x:Name="GridViewDataColumnNote" Width="250" DataMemberBinding="{Binding Notes, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}">
</telerik:GridViewDataColumn>

And the validation in the metadata file :

    [MetadataTypeAttribute(typeof(GabaritsEquipement.GabaritsEquipementMetadata))]
    [CustomValidation(typeof(Validations), "Test")]
    public partial class GabaritsEquipement
    {
...

And the Validations.shared.cs file :

public static ValidationResult Test(GabaritsEquipement donnees, ValidationContext context)
{
    string[] memberNames = new string[] { "Notes" };
    if (String.IsNullOrEmpty(donnees.Notes))
    {
        return new ValidationResult("Helppppppppppppppppppp", memberNames);
    }
    return ValidationResult.Success;
}

The fact is the member name Note is recognize because the cursor is positionned in the Notes field.  Problem, I don't the red box appear, just a normal ToolTip.

I have try different combinaison like this with no success :

DataMemberBinding="{Binding Notes, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnDataErrors=True}" ValidatesOnDataErrors="Default">
  
OR
  
DataMemberBinding="{Binding Notes, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnDataErrors=True}" ValidatesOnDataErrors="InEditMode"> ny Idea.



Every help will be very appreciate.
0
Nedyalko Nikolov
Telerik team
answered on 25 Feb 2011, 01:07 PM
Hi Louis Bouchard,

Unfortunately ValidatesOnDataErrors property doesn't work with DataAnnotation attributes it supports IDataErrorInfo and INotifyDataErrorInfo interfaces. Validation via DataAnnotation attributes is supported only when a cell or a row exits edit mode. In order to have validation in ViewMode you should implement either IDataErrorInfo or INotifyDataErrorInfo interface.

P.S. We will consider adding such validation support in view mode, but I cannot commit when we will add such validation.

Kind regards,
Nedyalko Nikolov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
Paul Brause
Top achievements
Rank 1
Answers by
Paul Brause
Top achievements
Rank 1
Louis Bouchard
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Share this question
or