Dave
Dave

Reputation: 241

Validate Input via ValidationRule for Datagrid binded to DataTable

Q: How can i manage that my dataGrid validation Rule validates my input after changing a row/cell and not before.

C: I have a datatgrid with autogenerated columns and a validation rule:

   <DataGrid x:Name="dataGrid"
                      RowDetailsVisibilityMode="VisibleWhenSelected" 
                      VerticalScrollBarVisibility="Auto"
                      HorizontalScrollBarVisibility="Auto"
                      EnableRowVirtualization="True"
                      AutoGenerateColumns="True"
                      ItemsSource="{Binding}"
                      SelectionMode="Extended">

                      <DataGrid.RowValidationRules>
                        <test:TableValidationRules/>
                      </DataGrid.RowValidationRules>
            </DataGrid>

The datagrid is binded to an dataTable after filling it with data from the database ....

        sqlAdapter.Fill(dataTable);
        dataGrid.DataContext = dataTable.DefaultView;

...

When i start my programmm all data is visualized as expected and the validation of the datagrid is triggered when building it. But if i add some new data into my dataGrid, e.g. in a new Row the validation occurs on the unchanged data without consideration of the data which i wrote into a certain cell.

It seems that i forgot some detail and that the solution is not far. Is it a binding-problem between dataTable and DataGrid? Or do i have to trigger the validation programatically? Whats best way to handle it?

Upvotes: 0

Views: 541

Answers (1)

Dave
Dave

Reputation: 241

The solution is to use ValidationStep property:

              <DataGrid.RowValidationRules >
                    <test:TableValidationRules ValidationStep="CommittedValue"/>
              </DataGrid.RowValidationRules>

Upvotes: 0

Related Questions