how to transfer all items of a list box to another list box in vb?
i want coding of dat.../
plz help...

your code will look like this . use this code at the click event of your list box.



For this example, both ListBox1 and ListBox2 have the Sorted property set to True.

Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        'add some words to ListBox1

        Dim words() As String = Split("Some luck lies in not getting what you thought you wanted but getting what you have which once you have got it you may be smart enough to see is what you would have wanted had you known")

        For Each word As String In words
            If Not ListBox1.Items.Contains(word) Then
            End If

    End Sub

    Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click

        'move the selected item from ListBox1 to ListBox2
        'after the move, select the next item in the list (if possible)

        Dim selected As Integer = ListBox1.SelectedIndex

        If selected >= 0 Then

            ListBox2.Items.Add(ListBox1.SelectedItem)           'add to list 2              
            ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)     'remove from list 1         

            If ListBox1.Items.Count > 0 Then                    'if list 1 is not empty     
                If selected = ListBox1.Items.Count Then         'if last item wasn't moved  
                    selected -= 1                               'point to last item         
                End If
                ListBox1.SelectedIndex = selected               'select last item           
            End If

        End If

    End Sub

    Private Sub btnRemove_Click(sender As System.Object, e As System.EventArgs) Handles btnRemove.Click

        If ListBox2.SelectedIndex >= 0 Then
        End If

    End Sub

End Class

how to transfer all items of a list box to another list box in vb?

In .Net you can use AddRange function of listbox.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
This article has been dead for over six months. Start a new discussion instead.