VB.NET Listbox Multiple select

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

    #1

    VB.NET Listbox Multiple select

    Hi,

    I have a list box lstMy which is bound to a datatable dt.
    The SelectionMode in the listbox is set to MultiSimple.

    I want to run through the listbox and return all _values_ from the selected items. In other words, if it were to be a single select listbox i would just refer to it as lstMy.SelectedV alue however in the multiple select I cannot do that. Plus I am running through the list using a for loop.

    Logically my code should look like this:

    for i = 0 to lstMy.Items.Cou nt -1

    if lstMy.Selected
    return lstMy.Item(i).V alue

    next i

    however, I can't make it work.

    Any help will be greatly appreciated.
    Thanks.

  • Lloyd Sheen

    #2
    Re: VB.NET Listbox Multiple select

    Dim ps As Object
    For Each ps In ListBox1.Select edItems
    doSomethingWith SelectedItem
    Next

    The SelectedItems does not show in MSDN (at least the Jan04).

    Lloyd Sheen

    "Alex Fimine" <alex.fimine@ni maxtech.com> wrote in message
    news:E6F585E1-DACE-4C81-AAB9-EDE4ECB5FF85@mi crosoft.com...[color=blue]
    > Hi,
    >
    > I have a list box lstMy which is bound to a datatable dt.
    > The SelectionMode in the listbox is set to MultiSimple.
    >
    > I want to run through the listbox and return all _values_ from the[/color]
    selected items. In other words, if it were to be a single select listbox i
    would just refer to it as lstMy.SelectedV alue however in the multiple select
    I cannot do that. Plus I am running through the list using a for loop.[color=blue]
    >
    > Logically my code should look like this:
    >
    > for i = 0 to lstMy.Items.Cou nt -1
    >
    > if lstMy.Selected
    > return lstMy.Item(i).V alue
    >
    > next i
    >
    > however, I can't make it work.
    >
    > Any help will be greatly appreciated.
    > Thanks.
    >[/color]


    Comment

    Working...