DataGrid clear validation errors

Dec 26, 2008 at 6:59 PM


I'm using WPF Datagrid bound to ObservableCollection of business objects.
The business object classes implement IDataErrorInfo.
The DataGrid uses row and cell level validations. The sample is bellow.

The issue is: in the scenario of validation error occured, then all cells in all rows become readonly unless the invalid data is corrected. I want to allow the user to delete invalid row if needed.
In this case the the DataGrid remains readonly and I did not find the way to reset it to edit mode again.
My main point: I want to control validation error for entire datagrid and clearv all of them when needed.

I tried even clearing validation error on the errornous cell's textbox, did not help:

DataGridRow row =



this.dataGridUserFields.ItemContainerGenerator.ContainerFromItem(sessionUserDataDefinition) as







if (row!=null)




BindingExpression bindingEx =



TextBox) ((DataGridTextColumn) this.dataGridUserFields.Columns[0]).GetCellContent(row)).






ReadOnlyObservableCollection<ValidationError> errors = Validation.GetErrors(



TextBox) ((DataGridTextColumn) this.dataGridUserFields.Columns[0]).GetCellContent(row)));



if (bindingEx!=null)







<dg:DataGrid Margin="20,20,0,10" Name="dataGridUserFields" SelectionMode="Single" AutoGenerateColumns="False" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" RowHeaderWidth="30" RowHeight="25" AlternationCount="1" CanUserAddRows="False" CanUserDeleteRows="False" AlternatingRowBackground="AliceBlue" SizeChanged="dataGridUserFields_SizeChanged" GridLinesVisibility="All" HeadersVisibility="All" IsSynchronizedWithCurrentItem="True"
                                     RowStyle="{StaticResource RowStyle}">
                                <PlugIn:RowDataInfoValidationRule ValidationStep="UpdatedValue" />
                            <dg:DataGrid.DataContext >
                                <Binding Path="SessionUserDataConfiguration"/>
                                    <!--<dg:DataGridTextColumn Header="ID" Binding="{Binding Path=ID}" Width="30" />-->
                                <dg:DataGridTextColumn Header="Field Name" Width="380" EditingElementStyle="{StaticResource CellEditStyle}">
                                    <dg:DataGridTextColumn.Binding >
                                        <Binding Path="FieldName" UpdateSourceTrigger="PropertyChanged">
                                            <PlugIn:CellDataInfoValidationRule ValidationStep="UpdatedValue"/>


Dec 30, 2008 at 9:30 AM

Pressing Escape key in the invalidated cell would allow you to edit other cells as well.

If you dont like to press Escape explicitly then you can alternately play with cell.IsEditing property to check i making it false can achieve what you need.

But I agree with the default behaviour that pressing escape gives user an alternate way to edit otehr cells as well when error occur.

Jan 2, 2009 at 7:56 PM


Thank you for the tips!

Escape key works for error clear purpose.
However, I need to achive that effect programmically, not by user.

Setting cell.IsEditing = false doesn't clear the error, my object that implement IDataErrorInfo interface and bound to the row still contains invalid data and remains invalid.


Jan 15, 2009 at 2:52 PM
Does calling DataGrid.CancelEdit() help?
Apr 12, 2010 at 11:31 AM

Did you manage to solve this? I have the same problem.

I want to be able to remove a row whether it failes validation or not. Tried the above without success. My grid is connected to an observable collection.

Also, How do I check to see if a row has a validation error? What do I send to Validation.HasError()?

Apr 12, 2010 at 12:54 PM

I found a solution for my problem.

I simply set the datagrids itemssource to null, and then set it back to my observable collection. This seems to cause the grid to reset clearing the validations.
Since 'm working from the observable collection, the row is gone.