[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?
Re: [02/03] Populating a listview based on a listbox in another form
you can do something like this
Code Code:
Dim i as integer
Dim num As Integer = my.forms.form1.listbox.Items.Count
For i = 0 To num - 1
My.forms.form2.listview.Items.Add(my.forms.from1.listbox.Items.Item(i))
Next
i don't made any testes, but i think that something similar to this should work!
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:
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?
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.
Re: [02/03] Populating a listview based on a listbox in another form
Quote:
Originally Posted by nmadd
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....