rickb
Freshman
I need to be able to move listbox items around a collection of up to 12 listboxes. For example, I move an item from listbox1 to listbox2; later, I need to move that same item from listbox2 to listbox3, and then on a future date move the item from listbox3 back to listbox1. I also need the item to be removed from its previous location when it moves to a new listbox.
Here is the code I have for moving items between 2 listboxes:
This is not original code from me; I got it from another site.
I modified this code to include a third listbox, but the modification doesn't remove the item from the its previous listbox (I added the listbox3 "Remove" code to the original DragDrop events and duplicated the MouseDown and DragEnter events); it copies it to the new listbox.
I appreciate any help or guidance.
Here is the code I have for moving items between 2 listboxes:
Code:
Private Sub listbox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
If ListBox1.SelectedIndex < 0 Then Return
ListBox1.DoDragDrop(ListBox1.Items(ListBox1.SelectedIndex).ToString, DragDropEffects.Copy Or DragDropEffects.Move)
End Sub
Private Sub listbox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox2.MouseDown
If ListBox2.SelectedIndex < 0 Then Return
ListBox2.DoDragDrop(ListBox2.Items(ListBox2.SelectedIndex).ToString, DragDropEffects.Copy Or DragDropEffects.Move)
End Sub
Private Sub listbox2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox2.DragEnter
e.Effect = DragDropEffects.All
End Sub
Private Sub listbox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragEnter
e.Effect = DragDropEffects.All
End Sub
Private Sub listbox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox2.DragDrop
If ListBox2.FindStringExact(e.Data.GetData(DataFormats.Text).ToString) = -1 Then
ListBox2.Items.Add(e.Data.GetData(DataFormats.Text).ToString)
ListBox1.Items.Remove(ListBox1.Items(ListBox1.SelectedIndex))
End If
End Sub
Private Sub listbox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop
If ListBox1.FindStringExact(e.Data.GetData(DataFormats.Text).ToString) = -1 Then
ListBox1.Items.Add(e.Data.GetData(DataFormats.Text).ToString)
ListBox2.Items.Remove(ListBox2.Items(ListBox2.SelectedIndex))
End If
End Sub
This is not original code from me; I got it from another site.
I modified this code to include a third listbox, but the modification doesn't remove the item from the its previous listbox (I added the listbox3 "Remove" code to the original DragDrop events and duplicated the MouseDown and DragEnter events); it copies it to the new listbox.
I appreciate any help or guidance.