Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. Public Sub New()
  2. InitializeComponent()
  3.  
  4. ListBox1.Items.Add("An item")
  5. ListBox1.Items.Add("Another item")
  6. ListBox1.Items.Add("This is an item too")
  7. ListBox1.Items.Add("This item is initially selected")
  8. ListBox1.Items.Add("Yet another item")
  9.  
  10. ListBox1.Sorted = True
  11. ListBox2.Sorted = True
  12. End Sub
  13.  
  14. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  15. MoveItem(ListBox1, ListBox2)
  16. End Sub
  17.  
  18. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  19. MoveItem(ListBox2, ListBox1)
  20. End Sub
  21.  
  22. Private Sub MoveItem(fromBox As ListBox, toBox As ListBox)
  23. If fromBox.SelectedIndex > ListBox.NoMatches Then
  24. Dim moveText As String = fromBox.Items(fromBox.SelectedIndex)
  25. fromBox.Items.RemoveAt(fromBox.SelectedIndex)
  26.  
  27. toBox.Items.Add(moveText)
  28. toBox.SelectedIndex = toBox.Items.IndexOf(moveText)
  29. End If
  30. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement