PDA

Click to See Complete Forum and Search --> : access other forms


carstenht
Aug 10th, 2007, 06:03 AM
hi
i have a project containing 2 forms. DB connection info is on form1 and i want to access this data from form2 - the data resides in textbox controls, but i cant "see" them from form2?? Something need the "public" keyword or???

nmadd
Aug 10th, 2007, 08:35 AM
Hi there,
Have a look at this thread first:
http://vbforums.com/showthread.php?t=481564

carstenht
Aug 10th, 2007, 08:54 AM
thanks, it looks promissing :)

carstenht
Aug 10th, 2007, 11:48 AM
hi again
i tried the approach described in the post, but i dont get any of the values. Other ways of doing this?

dynamic_sysop
Aug 10th, 2007, 12:06 PM
modify the constructor of Form2 to reference Form1...
Make the Control you wish to access Public instead of Private ( Modifiers = Public )

/// Form2 ...
public partial class Form2 : Form
{
private Form1 frm;
public Form2(Form f)
{
frm = (Form1)f;
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(frm.textBox1.Text);
}
}

and in Form1, to call form2 ...

Form2 frm2 = new Form2(this);
frm2.Show();

carstenht
Aug 10th, 2007, 01:57 PM
Thanks for your help guys, but i solved it by creating a class containing connection info, and pass this to the Show() method. Works like a charm :)

BramVandenbon
Aug 10th, 2007, 07:27 PM
Thanks for your help guys, but i solved it by creating a class containing connection info, and pass this to the Show() method. Works like a charm :)

Nice idea :)

carstenht
Aug 11th, 2007, 01:02 AM
thank you :p