Y could not move the listbox admin no to another leistox

Private Sub btnAssign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAssign.Click

    'If ListBoxassign.SelectedItem IsNot Nothing Then

    ListBoxall.Items.Add(ListBoxassign.SelectedItem)
    'End If
End Sub

Private Sub btnUnassign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnassign.Click
    ListBoxassign.Items.Remove(ListBoxassign.SelectedItem)
End Sub

End Class

Ow I think you want to transfer the selected item to another listbox I think but haven't testing this you need to trick it up with a selected item manner. Here is the sample but I'm not sure if the code will work but it for giving you the idea because I'm not near my laptop. Also try not using social network language (short cuts).

 ' Transfer Item to the second ListBox
 Dim Item_To_Transfer As String
 Item_To_Transfer = ListBox1.SelectedItem.ToString()
 ListBox2.Items.Add(Item_To_Transfer)
 ListBox1.Items.Remove(Item_To_Transfer)

 ' Transfer back to the first ListBox the Item.
 Dim Item_To_Transfer_Back As String
 Item_To_Transfer_Back = ListBox2.SelectedItem.ToString()
 ListBox1.Items.Add(Item_To_Transfer_Back)
 ListBox2.Items.Remove(Item_To_Transfer_Back)

Try out that and see if it solve your problem.

To move items from one to another is simple. After moving the item you can remove from the listbox items list by its selectedIndex value.

If Not ListBox1.SelectedItem = Nothing Then
    ListBox2.Items.Add(ListBox1.SelectedItem)
    ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
End If

Hope it can help you

Ow sorry, I tried separating the codes but it was combined when I posted it, from line 8 it a code to transfer back the item to the first control so from line1 to 7 it what you want then from line 8 to the end its for transferring back so please put it in two different buttons to see it working.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.