Results 1 to 5 of 5

Thread: [RESOLVED] [02/03] Populating a listview based on a listbox in another form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    115

    Resolved [RESOLVED] [02/03] Populating a listview based on a listbox in another form

    I have form1 that contains a listbox and form2 that contains a listview. I wish to populate the form2 listview with the info that is in the listbox from form1.

    What is the best way to pass/access the listbox from form 1 in form 2?

  2. #2
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: [02/03] Populating a listview based on a listbox in another form

    you can do something like this
    Code Code:
    1. Dim i as integer
    2.         Dim num As Integer = my.forms.form1.listbox.Items.Count
    3.  
    4.         For i = 0 To num - 1
    5.             My.forms.form2.listview.Items.Add(my.forms.from1.listbox.Items.Item(i))
    6.         Next

    i don't made any testes, but i think that something similar to this should work!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    115

    Re: [02/03] Populating a listview based on a listbox in another form

    Quote Originally Posted by mickey_pt
    you can do something like this
    Code Code:
    1. My.forms.form2.listview.Items.Add(my.forms.from1.listbox.Items.Item(i))
    "My" doesn't bring anything up when I type the . after it.

    The structure of my project is that I have a class called AppMgr with a Sub Main where I call form1 with the Application.Run method. I then have a command button in form 1 to launch form 2 using the form.ShowMethod.

    It is in form 2 where I wish to access the listbox of form 1.

    Shouldnt the frm1 object I instantiate in Sub Main be available in form 2?

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

    Re: [02/03] Populating a listview based on a listbox in another form

    Hi Jeff,
    Perhaps this post will be of help to you: http://vbforums.com/showthread.php?t=466253

    Good luck.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    115

    Re: [02/03] Populating a listview based on a listbox in another form

    Quote Originally Posted by nmadd
    Hi Jeff,
    Perhaps this post will be of help to you: http://vbforums.com/showthread.php?t=466253

    Good luck.

    ok - thanks for your help

    what i ended up doing was....
    1. creating a global variable in a module
    Public frm1 As Form1

    2. on form1 load assigning frm1 = me

    thus frm1 now pointed to the correct instance of form1 and was accessible in form 2

    i then used basically your code from above using fm1.listbox etc....

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