2014-01-08 108 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 

沿这些行的东西。关键是你必须为被丢弃的作品编写代码。