title: WPF visualtreehelper.getchildrencount returns 0 on datagrid
body: <p>I am using datagrid with 32 rows and when I try to use this GetCell(28,2) its fail, and also on row 28 - 32 there is the same problem.</p>
  
  <p>this one:  <code>visualtreehelper.getchildrencount</code> return 0 when its above row 28.</p>
  
  <p>I find out that if i roll down to those hidden rows on the datagrid I can get those rows with  GetCell() and its work fine.</p>
  
  <p>how i can do that without roll down?</p>
  
  <pre><code>    public DataGridCell GetCell(int row, int column)
      {
          DataGridRow rowContainer = GetRow(row);
  
          if (rowContainer != null)
          {
              DataGridCellsPresenter presenter = GetVisualChild&lt;DataGridCellsPresenter&gt;(rowContainer);
  
              DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column); 
              if (cell == null)
              {
                  datagrid_arinc_const.ScrollIntoView(rowContainer, datagrid_arinc_const.Columns[column]);
                  cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
              }
              return cell;
          }
          return null;
      }
  
      public DataGridRow GetRow(int index)
      {
          DataGridRow row = (DataGridRow)datagrid_arinc_const.ItemContainerGenerator.ContainerFromIndex(index);
          if (row == null)
          {
              datagrid_arinc_const.UpdateLayout();
              datagrid_arinc_const.ScrollIntoView(datagrid_arinc_const.Items[index]);
              row = (DataGridRow)datagrid_arinc_const.ItemContainerGenerator.ContainerFromIndex(index);
          }
          return row;
      }
  
      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;
      }
  </code></pre>