Search code examples
wpfdata-bindingdatagrid

Dynamically check the validation status of a cell in DataGrid


I have a dataGrid with a column which is binded with a double variable.

                <DataGrid Grid.Row="2" HeadersVisibility="Column" Name="ConsigneGrid" AutoGenerateColumns="False">
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding CALIBRATEUR, StringFormat=F3}" ClipboardContentBinding="{x:Null}" Header="Consigne" Width="*"/>
                </DataGrid.Columns>
            </DataGrid>

I would like to check the validity of the current cell value before dynamically commit and activate the edit mode of the following row.

I've tried to use the PreviewTextInput event. But I have only the new input char.

After, I've tried to use the IsValid property on the currentcell but, it doesn't updated.

Is there a way to check the validity of the cell (to be sure that the value is double).


Solution

  • I've a way to be sure to have a validation before commit.

    I've done a pre-check one each key press.

        private void Grid_Resultat_PreviewTextInput( object sender, TextCompositionEventArgs e )
        {
            e.Handled = !( Information.IsNumeric( e.Text ) || e.Text == "." || e.Text == "," || e.Text == "-" );
        }
    

    Thanks ! F.