Has anyone got some sample code to do drag and drop from one listbox to
another listbox using VB.Net 2005. The below code works for draging and
droping one at a time, but not for multiselected items. I tried setting up
an array to capture the selected items and then move them with the dragndrop
code, but after selecting the items when the user clicks on the items to
drag them the selection goes back to one item. Also I have code for the
listbox doubleclick event that moves whatever item is doubleclicked in one
listbox to the other. This worked fine until I added the dragndrop code to
the mousedown event, now instead of a doubleclick event I get two mousedown
events. I am sure someone has done this and I would appreciate seeing the
code.
Thanks
Thomas
Private Sub lstSelected_Dra gDrop(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles lstSelected.Dra gDrop
lstSelected.Ite ms.Add(e.Data.G etData(DataForm ats.Text).ToStr ing)
lstAvailable.It ems.Remove(e.Da ta.GetData(Data Formats.Text).T oString)
End Sub
Private Sub lstAvailable_Dr agDrop(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles lstAvailable.Dr agDrop
lstAvailable.It ems.Add(e.Data. GetData(DataFor mats.Text).ToSt ring)
lstSelected.Ite ms.Remove(e.Dat a.GetData(DataF ormats.Text).To String)
End Sub
Private Sub lstSelected_Dra gEnter(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles lstSelected.Dra gEnter
If (e.Data.GetData Present(DataFor mats.Text)) Then
e.Effect = DragDropEffects .Move
Else
e.Effect = DragDropEffects .None
End If
End Sub
Private Sub lstAvailable_Dr agEnter(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles lstAvailable.Dr agEnter
If (e.Data.GetData Present(DataFor mats.Text)) Then
e.Effect = DragDropEffects .Move
Else
e.Effect = DragDropEffects .None
End If
End Sub
Private Sub lstAvailable_Mo useDown(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles lstAvailable.Mo useDown
strDragDrop = lstAvailable.Te xt
lstAvailable.Do DragDrop(strDra gDrop, DragDropEffects .Move)
End Sub
Private Sub lstSelected_Mou seDown(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles lstSelected.Mou seDown
strDragDrop = lstSelected.Tex t
lstSelected.DoD ragDrop(strDrag Drop, DragDropEffects .Move)
End Sub
Private Sub lstAvailable_Mo useDoubleClick( ByVal sender As Object, ByVal e As
System.EventArg s) Handles lstAvailable.Do ubleClick
lstSelected.Ite ms.Add(lstAvail able.SelectedIt em)
lstAvailable.It ems.Remove(lstA vailable.Select edItem)
End Sub
Private Sub lstSelected_Dou bleClick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles lstSelected.Dou bleClick
lstAvailable.It ems.Add(lstSele cted.SelectedIt em)
lstSelected.Ite ms.Remove(lstSe lected.Selected Item)
End Sub
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
another listbox using VB.Net 2005. The below code works for draging and
droping one at a time, but not for multiselected items. I tried setting up
an array to capture the selected items and then move them with the dragndrop
code, but after selecting the items when the user clicks on the items to
drag them the selection goes back to one item. Also I have code for the
listbox doubleclick event that moves whatever item is doubleclicked in one
listbox to the other. This worked fine until I added the dragndrop code to
the mousedown event, now instead of a doubleclick event I get two mousedown
events. I am sure someone has done this and I would appreciate seeing the
code.
Thanks
Thomas
Private Sub lstSelected_Dra gDrop(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles lstSelected.Dra gDrop
lstSelected.Ite ms.Add(e.Data.G etData(DataForm ats.Text).ToStr ing)
lstAvailable.It ems.Remove(e.Da ta.GetData(Data Formats.Text).T oString)
End Sub
Private Sub lstAvailable_Dr agDrop(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles lstAvailable.Dr agDrop
lstAvailable.It ems.Add(e.Data. GetData(DataFor mats.Text).ToSt ring)
lstSelected.Ite ms.Remove(e.Dat a.GetData(DataF ormats.Text).To String)
End Sub
Private Sub lstSelected_Dra gEnter(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles lstSelected.Dra gEnter
If (e.Data.GetData Present(DataFor mats.Text)) Then
e.Effect = DragDropEffects .Move
Else
e.Effect = DragDropEffects .None
End If
End Sub
Private Sub lstAvailable_Dr agEnter(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles lstAvailable.Dr agEnter
If (e.Data.GetData Present(DataFor mats.Text)) Then
e.Effect = DragDropEffects .Move
Else
e.Effect = DragDropEffects .None
End If
End Sub
Private Sub lstAvailable_Mo useDown(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles lstAvailable.Mo useDown
strDragDrop = lstAvailable.Te xt
lstAvailable.Do DragDrop(strDra gDrop, DragDropEffects .Move)
End Sub
Private Sub lstSelected_Mou seDown(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles lstSelected.Mou seDown
strDragDrop = lstSelected.Tex t
lstSelected.DoD ragDrop(strDrag Drop, DragDropEffects .Move)
End Sub
Private Sub lstAvailable_Mo useDoubleClick( ByVal sender As Object, ByVal e As
System.EventArg s) Handles lstAvailable.Do ubleClick
lstSelected.Ite ms.Add(lstAvail able.SelectedIt em)
lstAvailable.It ems.Remove(lstA vailable.Select edItem)
End Sub
Private Sub lstSelected_Dou bleClick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles lstSelected.Dou bleClick
lstAvailable.It ems.Add(lstSele cted.SelectedIt em)
lstSelected.Ite ms.Remove(lstSe lected.Selected Item)
End Sub
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Comment