Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have two forms (Form1 & Form2). Form1 contains a DataGridView control and its related dataset and TableAdapter. How do I access them in Form2? I would like to write it like this:

addressTableAdapter1.Update(mpRetailDataSet1); //by creating objects of them is not working


Please reply with an example.



[orig. title]
how to get TableAdapter and DataSet of DataGridView in Another Windows Form
Posted
Updated 19-Jan-11 1:27am
v2

1 solution

Depending on which form creates the other, set up a public property in the created form which set to the DataSet and TableAdapter.

So, if Form1 create Form2, then Form2 has:
public DataSet dataToManipulate {get; set;}
public TableAdapter tableToManipulate {get; set;}

And Form1:
Form2 frm = new Form2();
frm.dataToManipulate = myDataSet;
frm.tableToManipulate = myTableAdapter;
frm.ShowDialog();
 
Share this answer
 
Comments
ks ravi 19-Jan-11 8:27am    
hi OriginalGriff,

thanks for reply, its working but showing Existing Form1(DataGridView form) Window along with new Form1.How to remove existing form or update to the existing form
Espen Harlinn 20-Jan-11 15:01pm    
5+ Nice and simple, OP should have been able to take it from here...

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