Code below, I have two list boxes. On the left is a list of driver strings and the right is the box that you can use the cmdMove or cmdMoveAll to add items to it. Additionally, there is a manual add text box to add items to the right listbox.

My question is, is there a way to validate and check for duplicates when attempting to add a new one manually or when you refresh the list on the left (which replenishes the list) from adding it again, or letting them add it (disappears from the left) but does not create duplicates on the right?

Thanks,

Jim

VB Code:
  1. Private Sub txtManualAdd_KeyDown(KeyCode As Integer, Shift As Integer)
  2.     If KeyCode = vbKeyReturn Then
  3.         cmdManualAdd.Value = True
  4.     End If
  5. End Sub
  6.  
  7. Private Sub cmdBack_Click()
  8.     ' Move one item from right to left
  9.     If lstRight.ListIndex >= 0 Then
  10.         lstLeft.AddItem lstRight.Text
  11.         lstRight.RemoveItem lstRight.ListIndex
  12.     End If
  13. End Sub
  14.  
  15. Private Sub cmdBackAll_Click()
  16.     ' Move all items from right to left.
  17.     Do While lstRight.ListCount
  18.         lstLeft.AddItem lstRight.List(0)
  19.         lstRight.RemoveItem 0
  20.     Loop
  21. End Sub
  22.  
  23. Private Sub cmdManualAdd_Click()
  24.     ' Verifies that the driver string begins with PCL
  25.     If Not Left$(LCase(txtManualAdd.Text), 5) = "PCL" Then
  26.         MsgBox "The driver string you are attempting to add is not PCL" _
  27.         , vbCritical, "Invalid Driver String"
  28.     Else
  29.         lstRight.AddItem txtManualAdd.Text
  30.     End If
  31. End Sub
  32.  
  33. Private Sub cmdMove_Click()
  34.     ' Move one item from left to right.
  35.     If lstLeft.ListIndex >= 0 Then
  36.         lstRight.AddItem lstLeft.Text
  37.         lstLeft.RemoveItem lstLeft.ListIndex
  38.     End If
  39. End Sub
  40.  
  41. Private Sub cmdMoveAll_Click()
  42.     ' Move all items from left to right
  43.         Do While lstLeft.ListCount
  44.             lstRight.AddItem lstLeft.List(0)
  45.             lstLeft.RemoveItem 0
  46.         Loop
  47. End Sub
  48.  
  49. Private Sub lstLeft_DblClick()
  50.     ' Simulate a click on the Move button.
  51.     cmdMove.Value = True
  52. End Sub
  53.  
  54. Private Sub lstRight_DblClick()
  55.     ' Simulate a click on the Bacl button.
  56.     cmdBack.Value = True
  57. End Sub