Question : Moving a selected item from listbox1 to listbox2

I have two listboxes: listbox1 and listbox2. When the user selects an item in listbox1 and click on Move button, the selected item will be moved to listbox2.

I have no problem in moving the selected item from listbox1 to listbox2 as follows:

            Dim item As Object
            Dim index As Integer
            item = listbox1.SelectedItem()
            index = listbox1.Items.IndexOf(item)
            listbox1.Items.RemoveAt(index)
            listbox2.Items.Add(item)

What I am facing is to be able to select the next item in listbox1 and make the moved item in listbox2 as selected.

Please advice me with a sample code snippet on how I could achieve this.

Answer : Moving a selected item from listbox1 to listbox2

try with:

            Dim item As Object
            Dim index As Integer
            item = listbox1.SelectedItem()
            index = listbox1.Items.IndexOf(item)
            listbox1.Items.RemoveAt(index)
            listbox1.SelectedIndex = index

            listbox2.Items.Add(item)
            listbox2.SelectedItem = item
Random Solutions  
 
programming4us programming4us