troubleshooting Question

Can anyone help me fix a InvalidCastException on VS windows forum C#

Avatar of Kep Deep
Kep Deep asked on
C#Microsoft Visual Studio
5 Comments2 Solutions240 ViewsLast Modified:
An unhandled exception of type 'System.InvalidCastException' occurred in mscorlib.dll

Additional information: Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible'.

        private void listgames_Click(object sender, EventArgs e)
        {
            DataRow drgameshop;
            int rowNo;

            rowNo = Convert.ToInt32(lstgames.SelectedValue);   //THIS IS WHERE THE ERROR OCCURS

            drgameshop = dscategory.Tables["Category"].Rows.Find(rowNo);

            lblCN.Text = drgameshop["Category.CategoryNo"].ToString();
            lblSN.Text = drgameshop["Stock.StockNo"].ToString();
            lblSD.Text = drgameshop["StockDesc"].ToString();
            lblQ.Text = drgameshop["Qty"].ToString();
            lblCP.Text = drgameshop["CostPrice"].ToString();
            lblSP.Text = drgameshop["SellingPrice"].ToString();
            lblRL.Text = drgameshop["ReOrderLevel"].ToString();
            lblRQ.Text = drgameshop["ReOrderQty"].ToString();
            lblSupNo.Text = drgameshop["Supplier.SupplierNo"].ToString();
            lblON.Text = drgameshop["OrderDetail.Orderno"].ToString();
            lblQO.Text = drgameshop["QtyOrdered"].ToString();
        }
    }
}
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros