title: wpf datagrid Ienumerable returning null
body: <p>Using C#.NET4.5, MS Visual Studio 2012, WPF.</p>
  
  <p>Hi guys got some code here that giving me null.  This code was a previous solution that I tried.  I received no errors but never tested through it since today when I found I debugged there rows were null.</p>
  
  <p>Heres the code:</p>
  
  <p>1st I throw my data I collected from SQL to a datatable and threw it into my datagrid...</p>
  
  <pre><code> private void LoadPareto(string pg)
   {
       DataTable tbl = new DataTable();
       tbl = mysqlq.SQL_GetPareto(pg);
       paretogrid.ItemsSource = tbl.AsDataView();
       // InsertColumns();
       ShowArrows();
   }
  </code></pre>
  
  <p>2nd set up binding in XAML...</p>
  
  <pre><code>&lt;DataGrid Name ="paretogrid" ItemsSource="{Binding}"
  </code></pre>
  
  <p>3rd I created an Ienumerable...</p>
  
  <pre><code>public IEnumerable&lt;System.Windows.Controls.DataGridRow&gt; GetDataGridRow(System.Windows.Controls.DataGrid grid)
  {
      var itemsource = grid.ItemsSource as System.Collections.IEnumerable;
      if (null == itemsource) yield return null;
      foreach (var item in itemsource)
      {
          var row = grid.ItemContainerGenerator.ContainerFromItem(item) as DataGridRow; // null?
          if (null != row) yield return row;
      }
  }
  </code></pre>
  
  <p>Then I call it in this method...</p>
  
  <pre><code>private void ShowArrows()
  {
      var rows = GetDataGridRow(paretogrid); // fetching null?
  
      foreach (DataGridRow r in rows)
      {
          DataRowView rv = (DataRowView)r.Item;
          foreach (DataGridColumn column in paretogrid.Columns)
          {
              if (column.GetCellContent(r) is TextBlock)
              {
                  TextBlock cellcontent = column.GetCellContent(r) as TextBlock;
                  MessageBox.Show(cellcontent.Text);
              }
          }
      }
  }
  </code></pre>
  
  <p>Now the Problem I have is in the Ienumerbale I see my item source contains 12007 records which is perfect. Yet when I step through I find ...</p>
  
  <pre><code>var row = grid.ItemContainerGenerator.ContainerFromItem(item) as DataGridRow;
  </code></pre>
  
  <p>Is returning null which my "if" statement find it as a false so skips the yield.
  So of course, when i go to step through the foreach loop in "showarrows" method It doesnt bother since there's null.</p>
  
  <p>So where am I going wrong? am I missing something?</p>
  
  <p>Thanks in advance guys n girls!</p>