moving items between two listboxes

Discussion in 'ASP .Net Web Controls' started by ASPirant, Nov 22, 2005.

  1. ASPirant

    ASPirant Guest

    Hi all,

    What I have is as follows:
    A drop-down box which when an item is selected, populates ListBox1. I
    then want to select an item ( or more) from ListBox1 to ListBox2 ( and
    vice versa).

    The problem I am trying to resolve currently, however, only transfers
    the item at the top of ListBox1 and not the one that I actually select
    which may be a few items below that. In summary, it ignores my
    selection and simply moves the the item at the top of the list! This is
    very annoying and I can't see what it is that I need to do to respond
    to my selection.

    I know that SelectedItem always points to the first item in the list.
    How do I identify the item that is actually selected??

    Any ideas? See partial code below.

    ----- start code ----
    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button1.Click, Button2.Click

    Dim btn As Button = CType(sender, Button)
    Dim lst As ListBox

    If btn Is Button1 Then
    lst = ListBox1
    lst = ListBox2
    End If

    Dim obj As Object = lst.SelectedItem

    If Not obj Is Nothing Then
    If lst Is ListBox1 Then
    End If
    End If
    End Sub

    ----- end code -----
    ASPirant, Nov 22, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.