VB.NET 2005 - Drag & drop between listboxes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • VB Programmer

    VB.NET 2005 - Drag & drop between listboxes

    In VB.NET 2005 (winform) any sample code to drag & drop items between 2
    listboxes? Thanks!


  • VB Programmer

    #2
    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]


    Comment

    • Bernie Yaeger

      #3
      Re: VB.NET 2005 - Drag &amp; 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.

      If you don't hear from me by this evening, please email me at
      berniey@optonli ne.net.

      Bernie Yaeger

      "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

      • Bernie Yaeger

        #4
        Re: VB.NET 2005 - Drag &amp; 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.



        If Index >= 0 Then

        frombox3.DoDrag Drop(frombox3.I tems(Index), DragDropEffects .Move)

        End If



        End Sub





        Private Sub tobox3_MouseDow n(ByVal sender As Object, ByVal e As
        System.Windows. Forms.MouseEven tArgs) Handles tobox3.MouseDow n

        Dim Pt As New Point(e.X, e.Y)

        Dim Index As Integer



        ' Determines which item was selected.



        tobox3 = sender

        Index = tobox3.IndexFro mPoint(Pt)



        ' Starts a drag-and-drop operation with that item.



        If Index >= 0 Then

        tobox3.DoDragDr op(tobox3.Items (Index), DragDropEffects .Move)

        End If



        End Sub





        Private Sub frombox3_DragDr op(ByVal sender As Object, ByVal e As
        System.Windows. Forms.DragEvent Args) Handles frombox3.DragDr op

        frombox3.Items. Add(e.Data.GetD ata(DataFormats .Text).ToString )

        tobox3.Items.Re move(e.Data.Get Data(DataFormat s.Text).ToStrin g)



        End Sub



        Private Sub tobox3_DragDrop (ByVal sender As Object, ByVal e As
        System.Windows. Forms.DragEvent Args) Handles tobox3.DragDrop

        tobox3.Items.Ad d(e.Data.GetDat a(DataFormats.T ext).ToString)

        frombox3.Items. Remove(e.Data.G etData(DataForm ats.Text).ToStr ing)



        End Sub

        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

        Working...