title: How can I create a datagrid validation dependency between columns
body: <p>I am trying to create a validation dependency between 2 datagrid columns. </p>
  
  <p>The first column is a drop down box. (DataGridTemplateColumn)
  The second is a text column. (DataGridTextColumn)</p>
  
  <p>I am trying from the drop down box event in the code behind to force the validation of the datagrid text column cell of the same row.</p>
  
  <p>Thanks for your help.</p>
  
  <pre><code>            &lt;data:DataGridTemplateColumn Header="Type" &gt;
                  &lt;data:DataGridTemplateColumn.CellTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;ComboBox ItemsSource="{Binding Source={StaticResource TypeListContainer}, Path=TypeLists}" Loaded="TypeBoxLoaded" DropDownClosed="TypeBoxChanged"&gt;
                          &lt;/ComboBox&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/data:DataGridTemplateColumn.CellTemplate&gt;
              &lt;/data:DataGridTemplateColumn&gt;
              &lt;data:DataGridTextColumn Header="Rule" Binding="{Binding RuleWrapper, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" x:Name="RuleCol" /&gt;
  </code></pre>
  
  <p>Here is the property</p>
  
  <pre><code>public string RuleWrapper
  {
      get
      {
          return this.Rule;
      }
      set
      {
          //Required
          if (value == null || value == string.Empty)
          {
              throw new ValidationException("Rule is required");
          }
          //Match regular expression if type is channel
          Regex reg = new Regex(@"^(51[01]|50[0-9]|[0-4]?[0-9][0-9]?)\.(51[01]|50[0-9]|[0-4]?[0-9][0-9]?)\.(51[01]|50[0-9]|[0-4]?[0-9][0-9]?)\.(51[01]|50[0-9]|[0-4]?[0-9][0-9]?)$");
          if (Type == "channel" &amp;&amp; !reg.IsMatch(value))
              throw new ValidationException("Channel not matching the right format");
  
          //Match range if type is trunk
          int intValue = -1;
          //Match if is a number
          if (int.TryParse(value, out intValue))
          {
              //Match if number is in the range
              if (intValue &lt; 0 || intValue &gt; 134217727)
                  throw new ValidationException("Trunk value must be between 0 and 134317727");
          }
          else
              throw new ValidationException("Trunk value must a an integer");
          this.Rule = value;
      }
  }
  </code></pre>