Submitting data from one form to another

wessamzeidan

Junior Contributor
Joined
Dec 8, 2002
Messages
379
Location
Lebanon
Hi, I have a small problem. I'm writing an application to access a database. I have multiple forms in the application. One form has a datagrid that displays data from a dataset. I want to be able to access the datagrid from another form to read a row selected by the user. I did this by changing the constructor of the second form to accept a datagrid, and used this constructor in the first form to pass an instance of the datagrid......I don't know if this is the right thing to do. If there is a better way to this, for example by setting the datagrid to be public, please tell me

Thanx in advance

WMZ
 
Nope, that is probably the best way of doing what you need to do. Passing a reference in the constructor is a good way of solving the problem of accessing something on one form from another.
 
So what I did was right, thanks alot.

One more question, can I pass a reference for the whole page if I want to access every thing in it?

Thanks again

WMZ
 
Yes, you certainly can. Remember to pass it as whatever your form name is, not just Form, if you want to be able to access your custom members on it. Failing that, you could cast it whenever you needed to.
 
Remeber that if you pass the form and you want to see the members (the controls, such as the DataGrid), you'll have to change their default protection level to public.

It sounds like your second form doesn't really need the grid, just some data from the selected row? If this is true, maybe the first form could extract whatever data is needed from the currently selected row and pass that to the second form. That's usually a simpler method than passing the control or Form reference. Just a thought.

-ner
 
Back
Top