vb.net forms application

G

Guest

I'm writing a vb.net forms application. I collect some information
in a listbox from the main form. Then I want to use that listbox
arraylist in another form on the same application. What's the
best way to get that information or listbox object to the next form.

After a submit button click I want to go to
newform.DefInstance.ShowDialog() and I want the listbox to be
available, in scope.

Much Thanks;

Segue
 
P

Peter Proost

Hi, you can use a property for that:
for example on the second form where you want to show the items, you add a
property:

Public Property myItems() As ListBox.ObjectCollection
Get
Return ListBox1.Items
End Get
Set(ByVal Value As ListBox.ObjectCollection)
ListBox1.Items.AddRange(Value)
End Set
End Property

and on the first form where you call the second form you do something like
this:

Dim frm2 As New Form2
frm2.myItems = ListBox1.Items
frm2.Show()

hth Greetz Peter
 
C

Cor Ligthert [MVP]

Seque,

You have only one form active in a time.
Passing to a showdialog form is commonly done as

\\\
dim frm2 as new form2
dim frm2.HisArraylist = myarraylist
frm2.showdialog
frm2.dispose
///

I hope this helps,

Cor
 
G

Guest

I couldn't figure out how to return the following though.
So I pre-empted the checkeditems and added them to
a normal listbox collection.

Public Property frmappnames() As CheckedListBox.ObjectCollection
Get
Return cmbflds2.Items
End Get
Set(ByVal Value As CheckedListBox.ObjectCollection)
cmbflds2.Items.Add(Value)
End Set
End Property
 
P

Peter Proost

Hi it works just the same, but you need to use the item.addrange method:

Public Property myItems() As CheckedListBox.ObjectCollection
Get
Return CheckedListBox1.Items
End Get
Set(ByVal Value As CheckedListBox.ObjectCollection)
CheckedListBox1.Items.AddRange(Value)
End Set
End Property

Dim frm2 As New Form2
frm2.myItems = CheckedListBox1.Items
frm2.Show()

hth Greetz Peter
 
C

Cor Ligthert [MVP]

Seque,

Any reason you won't use the simple sample I showed you, you were talking
about a showdialog form.

For that is in my idea a property a typing overkill.

What I did not write, that you can set in top of your dialogform

Friend HisArraylist as arraylist

If that is not yet there.

Is in my opininon is that more than enough for that.

However just mine opinion.

Cor
 
P

Peter Proost

Hi Segue I would also use Cor's example, because you're using a showdialog.
I overlooked that.

Greetz Peter
 
G

Guest

I could have cared less about the dialogue box.

Anyway this works if you're going from the main form to the 2nd form.

But how do you get the values from the 2nd form back to the main form.

Maybe I'm dense.
 
G

Guest

I could have cared less about the dialogue box.

Anyway this works if you're going from the main form to the 2nd form.

But how do you get the values from the 2nd form back to the main form.

Maybe I'm dense.
 
C

Cor Ligthert [MVP]

Segue,

In this sample you don't have to set anything back.

The arraylist is not transported, its address is transported.

I hope this helps,

Cor
 
G

Guest

Hmmm thnx for responding however, the order of the arraylist
is the same as it was before? I've tried quite a few things.
There must be something I'm not getting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top