Click here to Skip to main content
16,014,662 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this throws an exception "
C#
Unable to cast object of type 'System.Double' to type 'System.Collections.Generic.List`1[System.Int32]
"

What I have tried:

C#
List<int> gg = new List<int>();

...
C#
gg = (List<int>)metroGrid1.Rows[1].Cells[x].Value;
Posted
Updated 21-Feb-16 5:10am
Comments
Kornfeld Eliyahu Peter 21-Feb-16 9:35am    
And? What happened?
(Do all cells hold an integer value?)
_bluRe_ 21-Feb-16 10:02am    
no sir. it throws and exception in gg = (List<int>)metroGrid1.Rows[1].Cells[x].Value;
_bluRe_ 21-Feb-16 10:13am    
the values in the cells are integer value sir
Maciej Los 22-Feb-16 3:13am    
What is "metroGrid1"? Type the full name of control, like: Windows.Forms.DataGridView or WebForms.Grid, etc.

1 solution

In your code
C#
gg = (List<int>)metroGrid1.Rows[1].Cells[x].Value;

You are trying to get a single value from column x in the second row of the grid.

That value happens to be of type Double.

You can't assign a Double to a List (of int or any other type). But you can add the value to the list

Try using a for loop or a foreach loop to step through each of the cells you want and use the gg.Add() method to add the values to the List
 
Share this answer
 
Comments
_bluRe_ 21-Feb-16 23:59pm    
okay sir. will look for it later

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900