Casting DataGrid to Dataset  
Author Message
robben07160





PostPosted: Visual C++ General, Casting DataGrid to Dataset Top

Hi, I'm trying to cast DataGrid to Dataset see below (C++)

Dataset *mydataSet = __try_cast<DataSet*>(myDataGrid->DataSource);

However,  I get the following error: "Specified Cast is not Valid".

I'm trying to loop through the rows in the datagrid therefore I need to cast the datagrid to a dataset, I populate the datagrid with a datatable.

Would anyone have any suggestions on what I need to make it work

Thanks

 

 

 



Visual C++3  
 
 
Mike Danes





PostPosted: Visual C++ General, Casting DataGrid to Dataset Top

" I populate the datagrid with a datatable"

Then why do you expect to be able to cast the DataSource to a DataSet if you use a DataTable


 
 
robben07160





PostPosted: Visual C++ General, Casting DataGrid to Dataset Top

Hi Mike,

thanks for yuor reply, how would I then to do it as i am new to datagrids (VS 2003 .net)

Thanks in advance for your help!


 
 
Mike Danes





PostPosted: Visual C++ General, Casting DataGrid to Dataset Top

Try something like this:

DataTable *table = __try_cast<DataTable *>(myDataGrid->DataSource);

for (int i = 0; i < table->Rows->Count; i++)
{
DataRow *row = table->Rows->get_Item(i);

// do something with the row here

}


 
 
robben07160





PostPosted: Visual C++ General, Casting DataGrid to Dataset Top

Hi,

Thanks for that I will give it a go and will let you know how I get on.

Thanks for your help!


 
 
robben07160





PostPosted: Visual C++ General, Casting DataGrid to Dataset Top

cheers it worked!

Thanks