Below is a code snippet that iterates through your first ListBox and then adds it to the second, ensuring no duplicates are being added.
Firstly, make sure SelectionMode is set to Multiple on your ListBox.
Now you add the code to the button or whichever event triggers the move from the one ListBox to the Other.
lstChooseFields is the "from" Listbox and lstSelectedFields is the "to" Listbox
'An item must be selected If lstChooseFields.SelectedIndex > -1 Then Dim selectedItems = From i In lstChooseFields.Items Where i.Selected Select i For Each item In selectedItems 'Do not add duplicates If lstSelectedFields.Items.FindByValue(item.Value) Is Nothing Then lstSelectedFields.Items.Add(item) End If Next End If
No comments:
Post a Comment