Validation.HasError at the DataGridRowLevel

Nov 10, 2008 at 10:17 AM
Hi,

I have a DataGrid which contains a number of columns that perform validation on exception:

<dg:DataGrid.Columns>
    <dg:DataGridTextColumn Header="Name" Binding="{Binding Path=Name, ValidatesOnExceptions=True}"/>                    
    <dg:DataGridTextColumn Header="Age" Binding="{Binding Path=Age, ValidatesOnExceptions=True}"/>
</dg:DataGrid.Columns>

When a validation error occurs I can inspect the visual tree  and see that the Validation.HasError attached property is set to true for the TextBox that contains erroneous data. However this is not reflected at the DataGrid row level.

If I add a 'dummy' validation rule at the row level:

<dg:DataGrid.RowValidationRules>
    <local:RowDummyValidation ValidationStep="UpdatedValue" />
</dg:DataGrid.RowValidationRules>

Which always returns a positive result:

public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
{
    return ValidationResult.ValidResult;
}

When a validation error occurs I can now see that the Validation.HasError property is also set at the row level, and as a result the validation error indicator '!' is displayed.

My question is, why do I have to create a dummy validation rule and assocaite it with the row in order to have Validation.HasError  set at teh row level and for the error indicator to be displayed? Is this a bug/feature or am I doing something wrong?

Colin E.







Coordinator
Nov 10, 2008 at 1:37 PM
This is by design.  They are two different types of validations and require separate ways to declare intention.  The validation rules you set at the cell level affect item-level validation but it is sort of like an opt-in thing.