Iterating through rows of a data grid WPF
<p>how to iterate through every row of data grid view in WPF</p>

<pre><code>foreach (System.Data.DataRowView dr in grid.Items)
{
    string a = dr[0].ToString();
    MessageBox.show(a);
}
</code></pre>

<p>here I try to read all the values of first column!</p>

<p>It gives error:</p>

<blockquote>
  <p>An unhandled exception of type 'System.InvalidCastException' occurred in Test.exe<br>
      Additional information: Unable to cast object of type '&lt;>f__AnonymousType0`1[System.String]' to type 'System.Data.DataRowView'. </p>
</blockquote>

<p>How can I resolve this. please any one help me.</p>

<p>Thank you!</p>