title: Convert string to int using IValueConverter
body: <p>How do I convert string values to integers and back using IValueConverter? </p>
  
  <ul>
  <li>I have a database that consists of two tables; table CompanyX and table DeptY. </li>
  <li>Table CompanyX has field ID(int), firstName, lastName, Email, Phone. </li>
  <li>Table DeptY has field pID(int), Roles. </li>
  <li>DeptY pID is foreign key To CompanyX ID. Every time I select someone in the Combobox, I want it to display as their ID in a DataGrid.</li>
  </ul>
  
  <p>This is my ItemTemplate below:</p>
  
  <pre><code>&lt;Application.Resources&gt;
      &lt;DataTemplate x:Key="myTemplate"&gt;
          &lt;WrapPanel HorizontalAlignment="Stretch"&gt;
              &lt;TextBlock Text="{Binding FirstName}"/&gt;
              &lt;Label /&gt;
              &lt;TextBlock Text="{Binding LastName}"/&gt;
          &lt;/WrapPanel&gt;
      &lt;/DataTemplate&gt;
  &lt;/Application.Resources&gt;
  </code></pre>
  
  <p>This is my Combobox which is bound to the ItemTemplate:</p>
  
  <pre><code>&lt;ComboBox Height="23" HorizontalAlignment="Right" Margin="0,90,267,0" 
            Name="comboID"    ItemsSource="{Binding}" VerticalAlignment="Top" 
            Width="208" ItemTemplate="{StaticResource myTemplate}" /&gt;
  </code></pre>
  
  <p>And a DataGrid which displays:</p>
  
  <pre><code>&lt;DataGridTemplateColumn x:Name="pIDColumn" Header="Person ID" Width="auto"&gt;
      &lt;DataGridTemplateColumn.CellTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;TextBlock Text="{Binding Path=pID, Converter= {StaticResource myConverter}}"/&gt;   
          &lt;DataTemplate&gt;
      &lt;/DataGridTemplateColumn.CellTemplate&gt;                            
  &lt;/DataGridTemplateColumn&gt;
  &lt;DataGridTemplateColumn x:Name="rolesColumn" Header="Roles" Width="auto" &gt;
      &lt;DataGridTemplateColumn.CellTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;TextBlock Text="{Binding Path=Roles}"/&gt;
          &lt;/DataTemplate&gt;
      &lt;/DataGridTemplateColumn.CellTemplate&gt;
  &lt;/DataGridTemplateColumn&gt; 
  </code></pre>
  
  <p>IValueConverter which is not converting!!</p>
  
  <pre><code>public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  {
      string a = (string)value;
      int b;
      int.TryParse(a, out b);
      return b;
  }
  public object ConvertBack(object value, Type targetTypes, object parameter, System.Globalization.CultureInfo culture)
  {
      throw new NotImplementedException();
  }
  </code></pre>