title: WPF DataGrid changing row selection to a cell's TextBox
body: <p>I have a DataGrid and when the users hits the down arrow it need to move to next row below but focus on a cell that has a textbox in in.  I want to not focus on textbox not the actual cell.  This is what my DataGrid looks like;</p>
  
  <pre><code>&lt;DataGrid Name="myDataGrid" PreviewKeyDown="myDataGrid_PreviewKeyDown"&gt;
  &lt;DataGrid.Columns&gt;
      &lt;DataGridTemplateColumn Header="Description" IsReadOnly="True" Width="Auto"&gt;
          &lt;DataGridTemplateColumn.CellTemplate&gt;
              &lt;DataTemplate&gt;
                      &lt;TextBlock HorizontalAlignment="Right" Text="{Binding Path=Descrip, Mode=TwoWay, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged, StringFormat=C, ConverterCulture=en-us}" TextAlignment="Right"/&gt;
              &lt;/DataTemplate&gt;
          &lt;/DataGridTemplateColumn.CellTemplate&gt;
      &lt;/DataGridTemplateColumn&gt;
      &lt;DataGridTemplateColumn Header="Units Counted" Width="Auto"&gt;
          &lt;DataGridTemplateColumn.CellTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;TextBox BorderBrush="Black" BorderThickness="2" FontWeight="Bold" Margin="2" Text="{Binding Path=UnitCounted, Mode=TwoWay, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right" /&gt;
              &lt;/DataTemplate&gt;
          &lt;/DataGridTemplateColumn.CellTemplate&gt;
      &lt;/DataGridTemplateColumn&gt;
  &lt;/DataGrid.Columns&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>private void myDataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
      {
          if (e.Key == Key.Down)
          {
              e.Handled = true;
              int indx = myDataGrid.SelectedIndex + 1;
              myDataGrid.SelectedIndex = indx;
              myDataGrid.CurrentCell = new DataGridCellInfo(myDataGrid.Items[indx], myDataGrid.Columns[1])
          }
      }
  </code></pre>
  
  <p>Doing this selects the cell not the textbox.  If I add this to textbox;</p>
  
  <pre><code>FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}"
  </code></pre>
  
  <p>It adds a cursor to every row textbox but doesn't focus on the textbox.</p>
  
  <p>thanks</p>
  
  <p>edit:  Thanks to @Sheridan I am closer with this code;</p>
  
  <pre><code>&lt;TextBox 
  BorderBrush="Black" 
  BorderThickness="2" 
  FontWeight="Bold" 
  Margin="2" 
  Text="{Binding Path=UnitCounted, Mode=TwoWay, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}" 
  TextAlignment="Right" 
  FocusManager.IsFocusScope="True"
  FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}"/&gt;
  </code></pre>
  
  <p>Then in my <code>myDataGrid_PreviewKeyDown</code> adding in <code>myDataGrid.BeginEdit()</code> allows for it to work.  The problem is that it seems that BeginEdit never actually ends.  How do I fix this?</p>