views:

1622

answers:

1

I have a WPF DataGrid. I read a csv file and build an ObservableCollection of objects. I set the DataGrid.ItemsSource to the Collection. I would like to then force a RowValidation on every row in the DataGrid. If I, playing user, edit a cell, the RowValidation fires, all is well. But the Validation does not fire on the initial load. Is there some way I can call ??ValidateRow?? on a row? on every row? (C#, WPF, VS2008, etc)

A: 

For your bindings, set the UpdateSourceTrigger to property changed, and then put your validation rules inside that. The default update source trigger is Lost Focus.

  <Binding Path="Name" UpdateSourceTrigger="PropertyChanged">
            <Binding.ValidationRules>
                <ExceptionValidationRule />
            </Binding.ValidationRules>
        </Binding>

Also, for another good solution, have a look here

http://www.codeproject.com/KB/WPF/wpfvalidation.aspx

Paul builds a custom error provider, like

You can call the Validate() method on the ErrorProvider to force validation, and check if the controls are valid

amazedsaint