Results 1 to 3 of 3

Thread: set a reference in form2 to already open form1

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    set a reference in form2 to already open form1

    In VB6 you could call any public method or variable in Form1 from Form2 by qualifying it with Form1

    'IN FORM2

    msgbox Form1.txtName.Text

    in VB.NET though this doesnt work.

    Let says I have a listview on Form1 that I want to access from form2. If I assign the form to an instance variable of that form

    Dim x as New Form1
    x.ListView1

    this works, but it creates a new instance of Form1. If form1 is already open how can I set a reference to it in Form2 so I can access its controls?

  2. #2

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    http://msdn.microsoft.com/library/de...adingToNET.asp

    this is a good article talking about this if anyone else is interested

    How i solved my particular problem though, was to start the app from Sub Main in a module, and in the module my main form was declared as public, and that way it can be accessed by all other forms via its instance name.

  3. #3
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    Originally posted by kleinma
    http://msdn.microsoft.com/library/de...adingToNET.asp

    this is a good article talking about this if anyone else is interested

    How i solved my particular problem though, was to start the app from Sub Main in a module, and in the module my main form was declared as public, and that way it can be accessed by all other forms via its instance name.
    hehe, i just did a post very similiar to this only a few hours before this!
    http://www.vbforums.com/showthread.p...hreadid=290976
    its the last post, the thread i started ages ago so i wouldn't bother reading it, just the last post i included

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