vb.net - populate one listbox from another

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lolly

    #1

    vb.net - populate one listbox from another

    Hi all just wondering if any one has any idea on the following...

    I have two listboxes -

    one listbox populated from a database
    ListBox1.Items. Add(dr("NAME"))
    and the user can collect multiple items.

    The next listbox is populated from the selected items from Listbox1.

    I'm having trouble populating the Listbox2. Setting the datasource to
    Listbox1.Select edItems works but I want the user to have an option to
    clear the Listbox2 -
    ListBox1.ClearS elected()
    ListBox2.Items. Clear()

    But you cannot use this when the Datasource is set.

    I have tried this: ListBox2.Items. Add(ListBox1.Se lectedItems)

    But it doesnt work!!

    Thanks!!

  • RobinS

    #2
    Re: vb.net - populate one listbox from another

    Try cycling through them and adding them.

    For i As Integer = 0 to ListBox1.Select edIndeces.Count - 1
    ListBox2.Items. Add(FieldListBo x.SelectedIndec es(i))
    Next i

    Robin S.
    ------------------------

    "lolly" <lollypop.7@gma il.comwrote in message
    news:1174048205 .620049.60550@o 5g2000hsb.googl egroups.com...
    Hi all just wondering if any one has any idea on the following...
    >
    I have two listboxes -
    >
    one listbox populated from a database
    ListBox1.Items. Add(dr("NAME"))
    and the user can collect multiple items.
    >
    The next listbox is populated from the selected items from Listbox1.
    >
    I'm having trouble populating the Listbox2. Setting the datasource to
    Listbox1.Select edItems works but I want the user to have an option to
    clear the Listbox2 -
    ListBox1.ClearS elected()
    ListBox2.Items. Clear()
    >
    But you cannot use this when the Datasource is set.
    >
    I have tried this: ListBox2.Items. Add(ListBox1.Se lectedItems)
    >
    But it doesnt work!!
    >
    Thanks!!
    >

    Comment

    Working...