Exception of type 'System.InvalidCastException', Unable to cast object of type 'MS.Internal.NamedObject' to type 'System.Data.DataRowView'
<p>Code at front end:</p>
<pre><code>&lt;ListView Name=&quot;lvCus&quot; MouseDoubleClick=&quot;ListViewItem_DoubleClick&quot;&gt;
    &lt;ListView.View&gt;
        &lt;GridView AllowsColumnReorder=&quot;true&quot; ColumnHeaderToolTip=&quot;TbCus&quot;&gt;
            &lt;GridViewColumn Header=&quot;CusID&quot; Width=&quot;40&quot; DisplayMemberBinding=&quot;{Binding Path=CusID}&quot; /&gt;
            &lt;GridViewColumn Header=&quot;Firstname&quot; Width=&quot;120&quot; DisplayMemberBinding=&quot;{Binding Path=fn}&quot; /&gt;
            &lt;GridViewColumn Header=&quot;Lastname&quot; Width=&quot;120&quot; DisplayMemberBinding=&quot;{Binding Path=ln}&quot; /&gt;
            &lt;GridViewColumn Header=&quot;Dob&quot; Width=&quot;100&quot; DisplayMemberBinding=&quot;{Binding Path=dob}&quot; /&gt;
            &lt;GridViewColumn Header=&quot;Age&quot; Width=&quot;60&quot; DisplayMemberBinding=&quot;{Binding Path=age}&quot; /&gt;
        &lt;/GridView&gt;
    &lt;/ListView.View&gt;
&lt;/ListView&gt;
</code></pre>
<p>Below is the code at backend:</p>
<pre><code>private void ListViewItem_DoubleClick(object sender, RoutedEventArgs e)
{
   System.Data.DataRowView cusObj = (System.Data.DataRowView)lvCus.SelectedItem;
   var myobj = cusObj.Row.ItemArray;
   txtCusID.Text = myobj[0].ToString();    
   txtfn.Text = myobj[1].ToString();
   txtln.Text = myobj[2].ToString();
   txtdob.Text = myobj[3].ToString();
   txtage.Text = myobj[4].ToString();
}
</code></pre>
<p>ListView is loaded with data, and it seems to have one empty row at the end. When i click on empty row of ListView, i got following error:</p>
<blockquote>
<p>A first chance exception of type 'System.InvalidCastException' occurred in WpfApp.exe</p>
<p>Additional information: Unable to cast object of type 'MS.Internal.NamedObject' to type 'System.Data.DataRowView'.</p>
<p>If there is a handler for this exception, the program may be safely continued.</p>
</blockquote>
<p>I got above error, how can i resolve that? Guys, I am in learning phase.</p>