_DragDrop event not called

jinjouk

New member
Joined
May 14, 2008
Messages
3
Programming Experience
1-3
Hi, I have a program where i am trying to drag and drop controls within a table layout panel. I have normal controls created at runtime now and i assign a custom event handler to them:

PHP:
Private Sub custom_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)       
 Dim con As Control = DirectCast(sender, Control)        
con.DoDragDrop(con, DragDropEffects.Copy)  
  End Sub
i then have the table layout panels (some creted at runtime and some at design time) and give them these event handlers


PHP:
Private Sub custom_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs)    
    If e.Data.GetData(GetType(Control)) Then  
          e.Effect = DragDropEffects.Copy       
 Else        
    e.Effect = DragDropEffects.None  
      End If    
End Sub  

  Private Sub custom_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs)      
  Dim con As Control = DirectCast(e.Data.GetData(GetType(Control)), Control)         
MsgBox("pos = " & con.Location.X.ToString)  
  End Sub
The Drag enter function gets called, however If e.Data.GetData(GetType(Control)) always returns false, don't know why.

the main problem though is the dragdrop function is never called in the whole program, i don't know why, i have been through pages of examples on google and i seem to be doing exactly as they do but mines doesnt work.

anyone know why?
 
Use GetDataPresent method (not GetData) in DragEnter event, it returns Boolean value True/False whether the data type is present or not.
 
Back
Top