1

I´ve got 2 forms. If I click on a button on the first form I make the second panel popup which works fine. But I just cant seem to add items to the listbox on that other form. Beneath is an example of what I've got so far. Can anyone tell me what I'm doing wrong? Thanks in advance.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim Obj As New Form2
    Obj.ShowDialog()
    Form2.ListBox1.Items.Add("dafdfsafd")
End Sub
1
  • Perhaps you want Obj.Show() Commented Aug 1, 2013 at 19:09

1 Answer 1

3

If you want to add items to the other form's ListBox1, you'd need to use the instance you create:

Dim Obj As New Form2
Obj.ListBox1.Items.Add("dafdfsafd")
Obj.ShowDialog()

You'll also need to add the items before calling ShowDialog, or use Show (which doesn't block) instead.

Note that this will require ListBox1 to be Public on Form2.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot! I feel so stupid now as the answer was so obvious.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.