Re: VB.NET 2005 - Drag & drop between listboxes
Including, how can I reposition the item in the listbox by drag/drop?
"VB Programmer" <dont@emailme.c om> wrote in message
news:OKp8xOb4FH A.3036@TK2MSFTN GP15.phx.gbl...[color=blue]
> In VB.NET 2005 (winform) any sample code to drag & drop items between 2
> listboxes? Thanks!
>[/color]
Re: VB.NET 2005 - Drag & drop between listboxes
Hi,
I see that no one has answered this yet. I have done some work in this area
but I don't have the time to respond right now. I will respond this
evening, however. Sorry for the delay.
"VB Programmer" <dont@emailme.c om> wrote in message
news:OKp8xOb4FH A.3036@TK2MSFTN GP15.phx.gbl...[color=blue]
> In VB.NET 2005 (winform) any sample code to drag & drop items between 2
> listboxes? Thanks!
>[/color]
Re: VB.NET 2005 - Drag & drop between listboxes
Hi,
I've done some work on listbox (listview) drag/drop, but I have to
acknowledge that I have no way of reordering the items as they pass into the
'drop' box. However, I do know a little about this, so here's my answer.
I note that you mention vb .net 2005 specifically: I am not aware of a
difference between it and vb .net 2003 regarding drag/drop, but I apologize
if there are differences and it would be worth looking into.
BTW - MS is almost empty on the subject of drag/drop - a modest intro here
and there, but that's about it (and some of those are incorrect).
In any event, you have to modify the mousedown, dragdrop, and dragenter
events. I have code samples below. However, I have found that I have more
control using listviews instead of listboxes. For the listview to work, you
have to set the listview's view to smallicon mode; the rest is similar but
slightly different (the itemdrag event has also to be altered). I have
actually created a dual listview drag/drop control. If you would like to
see it, just email me at berniey@optonli ne.net, tell me your email address,
and I will send it to you.
HTH,
Bernie Yaeger
Private Sub frombox3_MouseD own(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles frombox3.MouseD own
Dim Pt As New Point(e.X, e.Y)
Dim Index As Integer
' Determines which item was selected.
frombox3 = sender
Index = frombox3.IndexF romPoint(Pt)
' Starts a drag-and-drop operation with that item.
Private Sub tobox3_DragEnte r(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles tobox3.DragEnte r
Dim x As Integer
x =
tobox3.FindStri ngExact(e.Data. GetData(DataFor mats.Text).ToSt ring, -1)
If x <> -1 Then
Exit Sub
End If
If (e.Data.GetData Present(DataFor mats.Text)) Then
e.Effect = DragDropEffects .Move
Else
e.Effect = DragDropEffects .None
End If
End Sub
Private Sub frombox3_DragEn ter(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles frombox3.DragEn ter
Dim x As Integer
x =
frombox3.FindSt ringExact(e.Dat a.GetData(DataF ormats.Text).To String, -1)
If x <> -1 Then
Exit Sub
End If
If (e.Data.GetData Present(DataFor mats.Text)) Then
e.Effect = DragDropEffects .Move
Else
e.Effect = DragDropEffects .None
End If
End Sub
"VB Programmer" <dont@emailme.c om> wrote in message
news:OKp8xOb4FH A.3036@TK2MSFTN GP15.phx.gbl...[color=blue]
> In VB.NET 2005 (winform) any sample code to drag & drop items between 2
> listboxes? Thanks!
>[/color]
Comment