Hi,

I need help with Listbox. I have two listboxes and when one selects from the listboxLeft it should go to listboxRight and that seems to be working fine. However, when I tried to remove the content from listboxRight and add it to the listboxLeft. The remove function is working, however it is not adding to the listboxLeft.

Also, when I click on 'moveall', it should move whatever in the listboxRight to the listboxLeft.

How do I go about these two things? Can somebody help me on that?

Thanks

this code for move item from listleft to listright :

Private Sub cmdRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemove.Click
        If ListLeft.Items.Count > 0 Then
            ListRight.Items.Add(ListLeft.SelectedItem)
            ListLeft.Items.Remove(ListLeft.SelectedItem)
        End If
    End Sub

this code to move all item on listleft to list right :

Private Sub cmdAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAll.Click
        Dim i, j As Integer
        If ListLeft.Items.Count > 0 Then
            For i = 0 To ListLeft.Items.Count - 1
                ListRight.Items.Add(ListLeft.Items.IndexOf(i))
            Next
        End If
    End Sub

Hi,

I have an another quick question, since I am new to vb.net..

I got all the listbox buttons working fine now..

When a user clicks on any of the buttons without choosing an item from the listbox, it should prompt an error saying 'please select an item'. How do I do that?

Thanks in advance!

Hi,

I have an another quick question, since I am new to vb.net..

I got all the listbox buttons working fine now..

When a user clicks on any of the buttons without choosing an item from the listbox, it should prompt an error saying 'please select an item'. How do I do that?

Thanks in advance!

this an example code.

Private Sub cmdRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemove.Click
    If ListLeft.SelectedIndex < 0 Then
        MsgBox("Please select an item", MsgBoxStyle.Exclamation, "Error")
    Else
        If ListLeft.Items.Count > 0 Then
            ListRight.Items.Add(ListLeft.SelectedItem)
            ListLeft.Items.Remove(ListLeft.SelectedItem)
        End If
    End If
End Sub

Hi,

I have a quick question. I have a listbox, on click 'all' btn, it should transfer to the right listbox. So, those are working fine. However, I have to prompt an error message when the user clicks the same button again, in where the data has been transfered to the right listbox. How do I do that?

Thanks

why you don't remove all item on left list, so none items well of in left list. all items has been moved to right list.
it make you don't have to prompt an error message when user click the same button.

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.