title: Why ItemContainerGenerator.ContainerFromIndex() returns null and how to avoid this behavior?
body: <p>I'm using this snippet to analyze the rows I've selected on a datagrid.</p>
  
  <pre><code>for (int i = 0; i &lt; dgDetalle.Items.Count; i++)
  {
      DataGridRow row = (DataGridRow)dgDetalle.ItemContainerGenerator.ContainerFromIndex(i);
      FrameworkElement cellContent = dgDetalle.Columns[0].GetCellContent(row);
      // ... code ...
  }
  </code></pre>
  
  <p>The cycle runs smoothly, but when processing certain indexes, the second line throws a null exception. MSDN's documentation says that <code>ItemContainerGenerator.ContainerFromIndex(i)</code> will return null if 'if the item is not realized', but this doesn't help me to guess how could I get the desired value.</p>
  
  <p>How can I scan all the rows? Is there any other way?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I'm using this snippet to read a <code>CheckBox</code> as explained <a href="https://stackoverflow.com/q/10502960/199419">here</a>. So I can't use binding or <code>ItemSource</code> at all unless I change a lot of things. And I cannot. I'm doing code maintenance. </p>