Simple validation on Cell?

Oct 7, 2008 at 12:08 AM
Hi guys,

is there any one who can show me a simple code how to validate a column? and if column is invalid display some message while using style, i am wokring hard to find solution but fail.

here what i have done, but i am unable to see the error in style.

in Panel Resource i have used below line


<Style x:Key="styTextBoxColumnStyleGif" TargetType="{x:Type TextBlock}">
     <Setter Property="Validation.ErrorTemplate">
                     <DockPanel LastChildFill="True">
                              <TextBlock DockPanel.Dock="Right" Foreground="Red" FontSize="14pt" Margin="-15,0,0,0" FontWeight="Bold">*</TextBlock>
                                      <Border BorderBrush="Red" BorderThickness="1">
                                             <AdornedElementPlaceholder />
              <Trigger Property="Validation.HasError" Value="true">
                       <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},Path=(Validation.Errors)[0].ErrorContent}" />
                       <Setter Property="Background" Value="LightSalmon"/>

and here is code for Grid



<toolkit:DataGrid Height="201" Name="grdDetail" Width="643" AutoGenerateColumns="False"  AlternationCount="2" CanUserAddRows="False"  CanUserSortColumns="False" AlternatingRowBackground="LightBlue" GridLinesVisibility="None"
IsSynchronizedWithCurrentItem="False" Background="Transparent" RowHeaderWidth="25" RowBackground="White" BorderThickness="0" BorderBrush="White" SelectionUnit="CellOrRowHeader" >
                   <toolkit:DataGridTemplateColumn Header="ID">      
TextBox Text="{Binding Path=ID,Mode=OneWay}" ></TextBox> <!-- this is Identity Column-->
                       <toolkit:DataGridTextColumn ElementStyle="{StaticResource styTextBoxColumnStyleGif}" >
                                       <Binding Path="Brand" ValidatesOnDataErrors="True">
                                                           <Validators:StringRangeValidationRule/>   <!-- See Blow for Code Behinde-->
                     <toolkit:DataGridTextColumn DataFieldBinding="{Binding Path=Password}" Header="Password"/>


And here is code behind for StringRangeValidation Rule.


public class StringRangeValidationRule : ValidationRule
        public override ValidationResult Validate(object value, CultureInfo culture)
                 ValidationResult result = new ValidationResult(true, null);
string inputString = (value ?? string.Empty).ToString();
                  if (inputString=="aqeel")
                        result =
new ValidationResult(false, "Please input some value");
                 return result;


i was finding the solution from net so thats why you can see many copy past code :D

please guys help me and that will help to all others beginner.

i have tried to understansd the

but the problem is i am using GRID and i want some thing in grid.


Oct 7, 2008 at 12:15 AM

Just more explanation regarding above problem, i can validate the column but problem is that i can not display error in tooltip or you can say unable to see style.

 hope that more help you , to solve my problem


Oct 10, 2008 at 2:11 PM
Is your repro similar to this thread,  If so then it is a known issue.