vb.net

drag and drop to tablelayoutpanel from listview


I am trying to build a control which implements a tablelayoutpanel for the design and placement of other controls within the control - I need to add functionality which will allow the tablelayoutpanel to accept content from a listview (It does not even need to process it in any fashion at this point) - I, however, can not get the tablelayout panel to even display that it will accept data - only displays the circle/slash symbol. These are kept in 2 separate child mdi forms within the same parent.

currently I have in my listview form

Private Sub Jboard_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.AllowDrop = True
    ListView2.AllowDrop = True
end sub
Private Sub ListView2_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragOver, ListView2.DragOver
    If e.Data.GetDataPresent(GetType(ListViewItem)) Then
        e.Effect = DragDropEffects.All
    End If
End Sub

Private Sub ListView2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView2.MouseDown
    Dim item As ListViewItem = ListView2.HitTest(e.Location).Item
    If item IsNot Nothing Then
        ListView2.DoDragDrop(item, DragDropEffects.All)
    End If
End Sub

on my new tablelayoutpanel control form I have

Me.AllowDrop = True
DboardScheduler1.AllowDrop = True
'dboardscheduler1 is my new control

in the code for the control I have

tablelayoutpanel1.AllowDrop = true

What am I missing?


Solution

  • It looks like you only coded the one side, you also need to tell the TLP(like) control how/what to do. Something like this (not sure of the constraints you want, like JUST LVs and only MOVE).

    ' NOT mousedown
    Private Sub ItemDrag(sender As Object, e As ItemDragEventArgs) Handles ...
       If e.Button <> Windows.Forms.MouseButtons.Left Then Exit Sub
    
       ' ToDo: Decide what to do with multiples.  Singles only assumed 
    
       ' add the item under the cusor as the first, effect as Move
       DoDragDrop(e.Item, DragDropEffects.Move)
    End Sub
    

    LV Drag OVer:

     ' probably:
     e.Effect = DragDropEffects.None
     ' because you cant really drop it here, but the No Action shows that it knows
     ' a D-D is happening.
    

    TLP Drag OVer:

     If (e.Data.GetDataPresent(GetType(ListViewItem)) = False) Then
           e.Effect = DragDropEffects.None
           Exit Sub
     Else
           e.Effect = DragDropEffects.Move     ' or link maybe
     End If
    

    TLP DragDrop:

      Dim dragLVI As ListViewItem 
    
     ' get text and do whatever with it
     If (e.Data.GetDataPresent(GetType(ListViewItem)) = False) Then
           e.Effect = DragDropEffects.None
           Exit Sub
     Else
         dragLVI = CType(e.Data.GetData(GetType(ListViewItem)), _
                                        ListViewItem)
         newTextThing = dragLVI.SubItems(0).Text
     End If
    

    Something along those lines. The point is that you have to write code for the piece being dropped on.