title: WPF Datagrid: How to change border thickness of a single cell programatically?
body: <p>Im new to WPF</p>
  
  <p>Im trying to change the border of a single cell depending on the column and row index.
  So far I already have the code for getting the column and row index.</p>
  
  <p>Now I need to get 'that cell' and change its border..</p>
  
  <p>This is my Code , but its not working:</p>
  
  <p>I got this method from net:</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);
              else
                  break;
          }    return child;
      }
  </code></pre>
  
  <p>Then this where I need to change the cell properties.. </p>
  
  <pre><code>           int rows = 0;
              int col = 0;
          while (col &lt; myDG.Columns.Count)
          {
              rows = 0;
              while (rows &lt; myDG.Items.Count)
              {
                  DataGridRow row = (DataGridRow)myDG.ItemContainerGenerator.ContainerFromIndex(rows);
  
                  if (row != null)
                  {
  
                      DataGridCellsPresenter presenter = GetVisualChild&lt;DataGridCellsPresenter&gt;(row);
                      DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(col);
  
                      cell.BorderThickness = new Thickness (2,2,2,2);
                      cell.BorderBrush= Brushes.Black;
  
  
                  rows++;
              }
              col++;
          }
  </code></pre>
  
  <p>Any Idea? Thanks in Advance </p>