Link to home
Start Free TrialLog in
Avatar of jvoros1
jvoros1

asked on

C# error "specified cast is not valid"

Hello Expert, I am getting an error when i try to do this
aDataSet = (DataSet) dataGrid1.DataSource;
Do you know why i would get specified cast is not valid i got it from
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridclassdatasourcetopic.asp so i am not sure why it would not work. Can you help me?
Thanks
ASKER CERTIFIED SOLUTION
Avatar of dfiala13
dfiala13

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Callandor
The example shows
DataSet* myDataSet;
myDataSet = dynamic_cast<DataSet*> (dataGrid1->DataSource);

You want to cast a pointer to an object, not cast the actual object.
Avatar of jvoros1
jvoros1

ASKER

Thanks for you help I see my problem now my dataGrid.DataSource = aDataTable not a aDataSet
so i changed it to aDataTable = (DataTable) dataGrid1.DataSource;
And it works great :)