Let us create a program that will exhibit a passing of data between listboxes. The events of our program is to put the entered text from txtname to lstdata1 and after putting it, we will erase the string inside the textbox. No empty string will be inputted inside the lstdata1 thus we will put a condition to prevent it to happen. If "To Right" or "To left" button is pressed, the selected data from lstdata1 will be transferred to lstdata2 or vice versa. If "All Right" or "All Left" button is pressed, all data inside the listbox will be transferred to the other listbox. Here is the code:
Private Sub cmdadd_Click()
If Trim(txtname.Text) <> "" Then
lstdata1.AddItem txtname.Text
End If
txtname.Text = ""
End Sub
Private Sub cmdallleft_Click()
Dim index As Integer
For index = 0 To lstdata2.ListCount - 1
lstdata1.AddItem lstdata2.List(index)
Next index
lstdata2.Clear
End Sub
Private Sub cmdallright_Click()
Dim index As Integer
For index = 0 To lstdata1.ListCount - 1
lstdata2.AddItem lstdata1.List(index)
Next index
lstdata1.Clear
End Sub
Private Sub cmdtoleft_Click()
If lstdata2.ListIndex <> -1 Then
lstdata1.AddItem lstdata2.List(lstdata2.ListIndex)
lstdata2.RemoveItem lstdata2.ListIndex
End If
End Sub
Private Sub cmdtoright_Click()
If lstdata1.ListIndex <> -1 Then
lstdata2.AddItem lstdata1.List(lstdata1.ListIndex)
lstdata1.RemoveItem lstdata1.ListIndex
End If
End Sub