Ok, this is the first time I've tried a serious use of Drag and Drop.

As a test, I first defined 2 instances of a very basic user control on a
form. The user control had one string type public property. All the dragdrop
event handlers needed were defined automatically by VS from the individual
instances (MouseDown, MouseMove, DragEnter, DragDrop). (This was all based
on that article http://msdn2.microsoft.com/en-us/library/aa289508(VS.71).aspx
- Implementing Drag and Drop in VisualBasic.Net)

This test worked fine. (I also went back and assigned a panel as the 2
usercontrols parent. It still works.)

Now in the real application, what I want to do is dynamically define a
number of usercontrols based on the data and attach them to a panel. In
other words, define a loop and for each record:

Dim x as new UserControl1
-- define it's properties
-- Attach the event handlers
AddHandler x.MouseDown, AddressOf ControlMouseDown
AddHandler x.DragDrop, AddressOf ControlDragDrop
AddHandler x.MouseMove, AddressOf ControlMouseMove
AddHandler x.DragEnter, AddressOf ControlDragEnter

Now the event handlers aren't firing, not even MouseDown. I've set the
AllowDrop property of each control instance to True. What else could I be
forgetting?

Re: Drag and Drop events not firing by James

James
Tue Oct 02 05:27:09 PDT 2007


"B. Chernick" <BChernick@discussions.microsoft.com> wrote in message
news:9280D259-9BAE-4F20-8110-6F0FA1D6CD42@microsoft.com...
> Ok, this is the first time I've tried a serious use of Drag and Drop.
>
> As a test, I first defined 2 instances of a very basic user control on a
> form. The user control had one string type public property. All the
> dragdrop
> event handlers needed were defined automatically by VS from the individual
> instances (MouseDown, MouseMove, DragEnter, DragDrop). (This was all
> based
> on that article
> http://msdn2.microsoft.com/en-us/library/aa289508(VS.71).aspx
> - Implementing Drag and Drop in VisualBasic.Net)
>
> This test worked fine. (I also went back and assigned a panel as the 2
> usercontrols parent. It still works.)
>
> Now in the real application, what I want to do is dynamically define a
> number of usercontrols based on the data and attach them to a panel. In
> other words, define a loop and for each record:
>
> Dim x as new UserControl1
> -- define it's properties
> -- Attach the event handlers
> AddHandler x.MouseDown, AddressOf ControlMouseDown
> AddHandler x.DragDrop, AddressOf ControlDragDrop
> AddHandler x.MouseMove, AddressOf ControlMouseMove
> AddHandler x.DragEnter, AddressOf ControlDragEnter
>
> Now the event handlers aren't firing, not even MouseDown. I've set the
> AllowDrop property of each control instance to True. What else could I be
> forgetting?
>
>

Is it possible to post a little more code for the page to see the full
picture of what is happening?

Thanks,
James Jardine


Re: Drag and Drop events not firing by BChernick

BChernick
Tue Oct 02 06:14:01 PDT 2007

No problem. Here it is:
This sub is called when SelectionChanged event of the dgFlow datagridview
fires. FtUtilDisplay is a property of the data layer pointing to a datatable
and pnlSegOrder is the panel control being used for a parent container.

Private MouseIsDown As Boolean = False
Private Sub RefreshSegmentOrderDisplay()
If dgFlow.CurrentRow IsNot Nothing Then

myDataManager.FillFtUtilDisplay(dgFlow.CurrentRow.Cells("FlowDataGridViewTextBoxColumn1").Value.ToString)
Dim dr As ftutilRow
Dim nX As Integer = 0
For Each dr In myDataManager.FtUtilDisplay.Rows
Dim si As New SegIcon
With si
.Sid = dr.sid
.AllowDrop = True
.Height = 60
.Width = 100
.Parent = pnlSegOrder
.Top = 2
.BorderStyle = BorderStyle.Fixed3D
.Left = nX
If pnlSegOrder.HorizontalScroll.Visible Then
pnlSegOrder.Height = si.Height + 25
Else
pnlSegOrder.Height = si.Height + 10
End If
si.Enabled = True
End With
AddHandler si.MouseDown, AddressOf IconMouseDown
AddHandler si.DragDrop, AddressOf IconDragDrop
' AddHandler si.DragOver, AddressOf IconDragOver
AddHandler si.MouseMove, AddressOf IconMouseMove
AddHandler si.DragEnter, AddressOf IconDragEnter

nX += si.Width + 5
Next
End If
End Sub

Private Sub IconMouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs)
' CType(sender, Label).DoDragDrop(sender, DragDropEffects.All)
MouseIsDown = True

End Sub

Private Sub IconMouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs)
If MouseIsDown Then
CType(sender, SegIcon).DoDragDrop(CType(sender, SegIcon).Sid,
DragDropEffects.Copy)

End If
MouseIsDown = False
End Sub

Private Sub IconDragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs)
If (e.Data.GetDataPresent(DataFormats.Text)) Then
' Display the copy cursor.
e.Effect = DragDropEffects.Copy
Else
' Display the no-drop cursor.
e.Effect = DragDropEffects.None
End If
End Sub

Private Sub IconDragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs)
CType(sender, SegIcon).Sid = e.Data.GetData(DataFormats.Text)

End Sub

-----------------------
The usercontrol itself, SegIcon is defined as follows
Public Class SegIcon

Private sFlow As String
Private sSid As String

Public Property Flow() As String
Get
Return sFlow
End Get
Set(ByVal value As String)
sFlow = value
End Set
End Property

Public Property Sid() As String
Get
Return sSid
End Get
Set(ByVal value As String)
sSid = value
lblMyLabel.Text = value
End Set
End Property

End Class

(No real code in that yet.)

"James Jardine" wrote:

>
> "B. Chernick" <BChernick@discussions.microsoft.com> wrote in message
> news:9280D259-9BAE-4F20-8110-6F0FA1D6CD42@microsoft.com...
> > Ok, this is the first time I've tried a serious use of Drag and Drop.
> >
> > As a test, I first defined 2 instances of a very basic user control on a
> > form. The user control had one string type public property. All the
> > dragdrop
> > event handlers needed were defined automatically by VS from the individual
> > instances (MouseDown, MouseMove, DragEnter, DragDrop). (This was all
> > based
> > on that article
> > http://msdn2.microsoft.com/en-us/library/aa289508(VS.71).aspx
> > - Implementing Drag and Drop in VisualBasic.Net)
> >
> > This test worked fine. (I also went back and assigned a panel as the 2
> > usercontrols parent. It still works.)
> >
> > Now in the real application, what I want to do is dynamically define a
> > number of usercontrols based on the data and attach them to a panel. In
> > other words, define a loop and for each record:
> >
> > Dim x as new UserControl1
> > -- define it's properties
> > -- Attach the event handlers
> > AddHandler x.MouseDown, AddressOf ControlMouseDown
> > AddHandler x.DragDrop, AddressOf ControlDragDrop
> > AddHandler x.MouseMove, AddressOf ControlMouseMove
> > AddHandler x.DragEnter, AddressOf ControlDragEnter
> >
> > Now the event handlers aren't firing, not even MouseDown. I've set the
> > AllowDrop property of each control instance to True. What else could I be
> > forgetting?
> >
> >
>
> Is it possible to post a little more code for the page to see the full
> picture of what is happening?
>
> Thanks,
> James Jardine
>
>

Re: Drag and Drop events not firing by BChernick

BChernick
Fri Oct 05 13:49:00 PDT 2007

Finally found the cause of the problem. A large portion of the user
control's surface was covered by a label. Clicking on the label did not
work. Clicking on bare control surface did. This has been a learning
experience. :-)

"James Jardine" wrote:

>
> "B. Chernick" <BChernick@discussions.microsoft.com> wrote in message
> news:9280D259-9BAE-4F20-8110-6F0FA1D6CD42@microsoft.com...
> > Ok, this is the first time I've tried a serious use of Drag and Drop.
> >
> > As a test, I first defined 2 instances of a very basic user control on a
> > form. The user control had one string type public property. All the
> > dragdrop
> > event handlers needed were defined automatically by VS from the individual
> > instances (MouseDown, MouseMove, DragEnter, DragDrop). (This was all
> > based
> > on that article
> > http://msdn2.microsoft.com/en-us/library/aa289508(VS.71).aspx
> > - Implementing Drag and Drop in VisualBasic.Net)
> >
> > This test worked fine. (I also went back and assigned a panel as the 2
> > usercontrols parent. It still works.)
> >
> > Now in the real application, what I want to do is dynamically define a
> > number of usercontrols based on the data and attach them to a panel. In
> > other words, define a loop and for each record:
> >
> > Dim x as new UserControl1
> > -- define it's properties
> > -- Attach the event handlers
> > AddHandler x.MouseDown, AddressOf ControlMouseDown
> > AddHandler x.DragDrop, AddressOf ControlDragDrop
> > AddHandler x.MouseMove, AddressOf ControlMouseMove
> > AddHandler x.DragEnter, AddressOf ControlDragEnter
> >
> > Now the event handlers aren't firing, not even MouseDown. I've set the
> > AllowDrop property of each control instance to True. What else could I be
> > forgetting?
> >
> >
>
> Is it possible to post a little more code for the page to see the full
> picture of what is happening?
>
> Thanks,
> James Jardine
>
>