SplitContainer with form ListBox how to add items?

0

How can I add items in a ListBox inside a form, and the form inside a SplitContainer.

Button (Load ListBox) [home.vb (WindowsForm)]:

Dim naveg As New frmListBox
naveg.TopLevel = False
SplitContainer1.Panel2.Controls.Add(naveg)
naveg.Show()

Button (Add item) [home.vb (WindowsForm)]:

adicionarItems("Testando...")

ListBox [frmListBox.vb (WindowsForm)] is borderless and has full listbox anchors.

Functions [ex.functions.vb (Modules)]

Public Function adicionarItems(ByVal valor As String)
    frmListBox.ListBox1.Items.Add(valor)
End Function

Above is all the data, how can I add items in the listbox, within Split? I was searching, would it be by Controls?

    
asked by anonymous 19.10.2015 / 00:25

1 answer

0

First option

I did not really understand your question, but you could create a loop by checking each type of control that is in the SplitContainer, and after finding the Form, execute the command. Here's the example:

Public Sub AdicionarItem(ByRef Container As SplitContainer, ByVal oQueAdicionar As Object)
    For Each x As Control In Container
        If TypeOf x Is ListBox ' O Objeto é ListBox?
             CType(x, ListBox).Items.Add(oQueAdicionar)
        End If
    Next
End Sub

Second option

You can declare this ListBox as a WithEvents public, follow the example below.

Place this line below the class declaration of your initial Form:

  Public Class Form1 'ou Home....
       Public WithEvents naveg As frmListBox

And this code in the Button (Load ListBox) [home.vb (WindowsForm)]:

  naveg = New frmListBox
  naveg.TopLevel = False
  SplitContainer1.Panel2.Controls.Add(naveg)
  naveg.Show()

So what do you do, create this method (it's the same, but improved):

  Public Function adicionarItems(ByVal valor As String)
       Call Form1.naveg.Items.Add(valor)
       'Lembrando, que em "Form1" é o nome da sua classe inicial.
  End Function

Try to do this, if you have any questions, comment here.

    
19.10.2015 / 04:45