Results 1 to 8 of 8

Thread: access other forms

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    162

    access other forms

    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???

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: access other forms

    Hi there,
    Have a look at this thread first:
    http://vbforums.com/showthread.php?t=481564

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    162

    Re: access other forms

    thanks, it looks promissing

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    162

    Re: access other forms

    hi again
    i tried the approach described in the post, but i dont get any of the values. Other ways of doing this?

  5. #5
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: access other forms

    modify the constructor of Form2 to reference Form1...
    Make the Control you wish to access Public instead of Private ( Modifiers = Public )
    Code:
    /// 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 ...
    Code:
        Form2 frm2 = new Form2(this);
        frm2.Show();
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    162

    Re: access other forms

    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

  7. #7
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 2002
    Location
    Belgium
    Posts
    502

    Re: access other forms

    Quote Originally Posted by carstenht
    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
    ____________________________________________

    Please rate my messages. Thank you!
    ____________________________________________
    Bram Vandenbon
    http://www.bramvandenbon.com

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    162

    Re: access other forms

    thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width