Click here to Skip to main content
15,920,603 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am trying to drag files from Explorer to my control (a panel)

Initialising code:
VB
Friend Const CtrlMask As Byte = 8

VB
'
'ListView
'
Me.AllowDrop = True
Me.Controls.Add(Me.MainPanel)
Me.Controls.Add(Me.ToolPanel)
Me.Name = "ListView"
Me.ViewMenu.ResumeLayout(False)
Me.ResumeLayout(False)

In the code:
VB
Private Sub ListView_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
   Dim f As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
   Select Case e.Effect
      Case DragDropEffects.Copy : RaiseEvent FilesDropped(f, True)
      Case DragDropEffects.Move : RaiseEvent FilesDropped(f, False)
   End Select
End Sub

Private Sub ListView_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
   If (e.KeyState And CtrlMask) = CtrlMask Then e.Effect = DragDropEffects.Copy Else e.Effect = DragDropEffects.Move
End Sub

I put a breakpoint on DragEnter but it never gets there.

I cannot see what I am doing wrong. Can anyone else?
Posted

1 solution

You cannot set your form/panel's AllowDrop and expect it's child controls to become drop targets. Set your ListView control's AllowDrop to true instead.
 
Share this answer
 
Comments
Stuart Nathan 25-Apr-11 13:39pm    
Listview (first) code above shows Me.AllowDrop = True

Should the form it is on also be set true, although I have tried all combinations.
strogg 25-Apr-11 14:08pm    
Try this. Create a new form, add a list view & set AllowDrop to true in the properties, nothing else.
Add a DragEnter event, put some code to test like - Console.Beep(1000,500) in it & try. It's working for me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900