Forced confirmation WPF, DataGrid, ObservableCollection

I have a DataGrid WPF. I read the csv file and built ObservableCollection of objects. I set the DataGrid.ItemsSource to the collection. I would like to force RowValidation to use every row in the DataGrid. If I, playing the user, edit the cell, start RowValidation, all is well. But the check does not work on boot. Is there any way I can name? ValidateRow ?? by line? on each line? (C #, WPF, VS2008, etc.)

+7
validation wpf datagrid wpf-controls
source share
2 answers

For your bindings, change the UpdateSourceTrigger property and change the validation rules. The default update source trigger is lost focus.

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

Also, for another good solution, look here.

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

Paul creates his own error provider, for example

You can call the Validate () method on ErrorProvider to force validation, and verify that the controls are correct.

+2
source share

You will need to set the RowValidationRule and set ValidationStep = "ConvertedProposedValue" if you want it to check after the bootstrap ObservableCollection

  <DataGrid Name="dgCsvObjects" ItemsSource="{Binding Path=CsvObjects}" AutoGenerateColumns="False"> <DataGrid.RowValidationRules> <Validation:MyObjectValidationRule ValidationStep="ConvertedProposedValue" /> </DataGrid.RowValidationRules> <DataGrid.Columns> <DataGridTextColumn Header="Property1" Binding="{Binding Path=Property1}" /> <DataGridTextColumn Header="Property2" Binding="{Binding Path=Property2}" /> <DataGridTextColumn Header="Property3" Binding="{Binding Path=Property3}" /> <DataGridTextColumn Header="Property4" Binding="{Binding Path=Property4}" /> </DataGrid.Columns> </DataGrid> 
+1
source share

All Articles