Validation d'une cellule dans un dataGrid
Bonjour tout le monde,
Alors j'ai une dataGrid que je remplie a la"main" donc je dois contrôler l'entrée clavier.
Dans un cas c'est le type String ou Date ou Double, j'ai essayer avec ValidatesOnExceptions=True et
Code:
1 2 3 4 5 6 7 8 9
| <Style x:Key="datagridElStyle" TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="Background" Value="Yellow" />
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style> |
ce code pour changer le style de ma cellule en cas d'erreur mais je n'arrive pas a résoudre ce mystère
mon xaml est le suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| <Style x:Key="datagridElStyle" TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="Background" Value="Yellow" />
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
</lib:dataGrid.Resources>
<lib:dataGrid.Columns>
<DataGridTextColumn ElementStyle="{StaticResource datagridElStyle}" Width="*" x:Name="abs" Header="Abscisse" Binding="{Binding Path=X, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,ValidatesOnExceptions=True,ValidatesOnDataErrors=True}"/> |
mon Code Behind
Code:
1 2 3
| If Not (IsDate(dgabs.SelectedItem.X)) Then
Throw New ArgumentException("Not a Date")
End If |
J'ai louper quelques chose?
Merci de votre aide