Urgent, plz help

G

Guest

Hi

I just have a quick databinding question. I have 2 forms.....
Form1 is my main form containing all the controls i want to bind the results of my query to
Form2 contains a datagrid containing a list of guests in the database. The user can click on a row to select a guest. They then hit the OK button. This will then run a query to retrieve that guests details from my database (this woks fine). What i now want to do is bind the results of the query that is run from Form2 to the controls (textboxes) on Form1.

Does anyone know how to do this?
I know how to bind to controls on the same form but not when they are on a differnt form!!

This is what i normally use...
Me.txtFName.DataBindings.Add(New Binding("Text", ds.Tables("Guest"), "F_Name")

in VB6 i would just replace 'Me' with the name of the other form, but this does not seem to work in VB.NET!!!
i.e
Form1.txtFName.DataBindings.Add(New Binding("Text", ds.Tables("Guest"), "F_Name")

when i try the above i get the following error
Reference to a non shared member requires an onject refernc

Can anyone please help me
Many thx
 
M

Mohamoss

Hi
If form one is the caller of form two . I.e. you create and open from2
somewhere inside form1. Then form1 has a reference to form2 but not the
opposite. One way to over come that is to pass a reference to the object
that you want to bind in form1 to the constructor of form2. you have to
write new constructor for form2 that take a textbox( textboxes) . on form1
while creating form2 pass reference to the textboxes that will be binded
from form one .
So you will do something like this
Form2 theotherform = new Form2 ( this.whatevertextbox , ……)
Then in form two save these references in some object just to bind later.
This is not a good solution whoever since this will cause a circular
reference which means bad design
Why don't you send the query result to form1 some way, then you can do the
binding from there.
hope that helps,
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top