2014-01-08 107 views
0

我想建立一個實現在控制範圍之內的設計和其他控件放置一個TableLayoutPanel控件TableLayoutPanel中 - 我需要添加功能,這將允許TableLayoutPanel中從一個ListView接受的內容(它甚至不需要以任何方式處理它) - 但是,我不能讓桌面佈局面板甚至顯示它將接受數據 - 只顯示圓/斜槓符號。這些保存在同一父母的兩個獨立的兒童mdi表格中。拖放從列表視圖

目前我已經在我的列表視圖形式

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 

我的新TableLayoutPanel控件的形式對我有

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

在控件的代碼,我有

tablelayoutpanel1.AllowDrop = true 

什麼時我錯過了?

+0

你在TLP.DragOver事件作出迴應,顯示的是你會接受什麼樣的被拖動,它是如何被拖動(移動VS複製)爲drageffects,然後在TLP.DragDrop實際接受項目(S) – Plutonix

+1

...雖然這可能是一個設計時間問題...很難說(事件消耗看起來更像運行時)。您應該在ItemDrag事件中啓動DoDragDrop,以便您可以告訴另一方更多信息(如移動或複製)。另外你如何將一個ListView ** Item **拖放到TLP之類的東西上?來源永遠不會接受它。 – Plutonix

+0

理想我會拖累ListView項的TLP將啓動程序上的解決方案須─LV的項目有哪些可以檢索所需的所有數據的第一列中的編號顯示的內容 - 老實說,我只需要做出TLP接受下降和保存ListView2.SelectedItems(0).SubItems(0)。文本,以在控制方面 –

回答

1

它看起來像你只編碼的一面,還需要告訴TLP(像)控制如何/怎麼做。像這樣的東西(不確定你想要的約束,比如JUST LV和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拖過:

' 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拖過:

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 

沿這些行的東西。關鍵是你必須爲被丟棄的作品編寫代碼。