title: set value in cell in datagrid in wpf in c#
body: <p>i want to set a value in a specific cell in wpf 
  and i use this code but getRow and getCell method show this error</p>
  
  <blockquote>
    <p>'DataGrid' does not contain a definition for 'GetRow' and no extension method 'GetRow' accepting a first argument of type 'DataGrid' could be found (are you missing a using directive or an assembly reference?) </p>
    
    <p>'DataGrid' does not contain a definition for 'GetCell' and no
    extension method 'GetCell' accepting a first argument of type
    'DataGrid' could be found (are you missing a using directive or an
    assembly reference?)  ControlSolution.Form</p>
  </blockquote>
  
  <p>and error in     public partial class UCfrmRaafaLevelsUp : UserControl</p>
  
  <blockquote>
    <p>Extension method must be defined in a non-generic static class    </p>
  </blockquote>
  
  <p>the code i use it</p>
  
  <pre><code>    public static T GetVisualChild&lt;T&gt;(Visual parent) where T : Visual
  {
      T child = default(T);
      int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
      for (int i = 0; i &lt; numVisuals; i++)
      {
          Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
          child = v as T;
          if (child == null)
          {
              child = GetVisualChild&lt;T&gt;(v);
          }
         if (child != null)
         {
             break;
         }
     }
         return child;
  }
  
  public static DataGridRow GetSelectedRow(this DataGrid grid)
  {
      return (DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem);
  }
  public static DataGridRow GetRow(this DataGrid grid, int index)
  {
      DataGridRow row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromIndex(index);
      if (row == null)
      {
          // May be virtualized, bring into view and try again.
          grid.UpdateLayout();
          grid.ScrollIntoView(grid.Items[index]);
          row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromIndex(index);
      }
      return row;
  }
  
  public static DataGridCell GetCell(this DataGrid grid, DataGridRow row, int column)
  {
      if (row != null)
      {
          DataGridCellsPresenter presenter = GetVisualChild&lt;DataGridCellsPresenter&gt;(row);
  
          if (presenter == null)
          {
              grid.ScrollIntoView(row, grid.Columns[column]);
              presenter = GetVisualChild&lt;DataGridCellsPresenter&gt;(row);
          }
  
          DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
          return cell;
      }
      return null;
  }
  
  public static DataGridCell GetCell(this DataGrid grid, int row, int column)
  {
      DataGridRow rowContainer = grid.GetRow(row);
      return grid.GetCell(rowContainer, column);
  }
  </code></pre>
  
  <p>in this post
  <a href="https://stackoverflow.com/questions/12164079/change-datagrid-cell-value-programmatically-in-wpf">Change DataGrid cell value programmatically in WPF</a></p>