Tuesday, July 23, 2013

how to move items from left to right and right to left list box

While moving the items from left listbox to right listbox

For Each item As ListItem In lbxLeft.Items
                If item.Selected And Not lbxRight.Items.Contains(item) Then
                    Dim newItem As New ListItem(item.Text, item.Value)
                    lbxRight.Items.Add(newItem)
                    itemsToRemove.Add(item)
                End If
            Next
            For Each item As ListItem In itemsToRemove
                lbxLeft.Items.Remove(item)
            Next


While moving items from right to left

 Dim itemsToRemove As New List(Of ListItem)
            For Each item As ListItem In lbxRight.Items
                If item.Selected And Not lbxLeft.Items.Contains(item) Then
                    Dim newItem As New ListItem(item.Text, item.Value)
                    lbxLeft.Items.Add(newItem)
                    itemsToRemove.Add(item)
                End If
            Next
            For Each item As ListItem In itemsToRemove
                lbxRight.Items.Remove(item)
            Next

On Submit click

For Each item As ListItem In lbxRight.Items
         'do something
Next

No comments:

Post a Comment