StartDrag Method

Applies To

DataObject object.

Description

Initiates a drag-and-drop operation for a DataObject.

Syntax

fmDropEffect=Object.StartDrag([Effect as fmDropEffect])

The StartDrag method syntax has these parts:

Part

Description

Object

Required. A valid object.

Effect

Optional. Effect of the drop operation on the target control.


Settings

The settings for Effect are:

Constant

Value

Description

fmDropEffectNone

0

Does not copy or move the drop source to the drop target.

fmDropEffectCopy

1

Copies the drop source to the drop target.

fmDropEffectMove

2

Moves the drop source to the drop target.

fmDropEffectCopyOrMove

3

Copies or moves the drop source to the drop target.


Remarks

The drag action starts at the current mouse pointer position with the current keyboard state and ends when the user releases the mouse. The effect of the drag-and-drop operation depends on the effect chosen for the drop target.

For example, a control's MouseMove event might include the StartDrag method. When the user clicks the control and moves the mouse, the mouse pointer changes to indicate whether Effect is valid for the drop target.

See Also

BeforeDragOver event, BeforeDropOrPaste event.

Example

The following example demonstrates a drag-and-drop operation from one ListBox to another using a DataObject to contain the dragged text. This code sample uses the SetText and StartDrag methods in the MouseMove event to implement the drag-and-drop operation.

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains two ListBox controls named ListBox1 and ListBox2. You also need to add choices to the second ListBox.

Private Sub ListBox2_BeforeDragOver(ByVal Cancel As MSForms.ReturnBoolean, _
        ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y _
        As Single, ByVal DragState As Long, ByVal Effect As MSForms. _
        ReturnEffect, ByVal Shift As Integer)
    Cancel = True
    Effect = 1
End Sub

Private Sub ListBox2_BeforeDropOrPaste(ByVal Cancel As MSForms.ReturnBoolean, _
        ByVal Action As Long, ByVal Data As MSForms.DataObject, ByVal _
        X As Single, ByVal Y As Single, ByVal Effect As MSForms. _
        ReturnEffect, ByVal Shift As Integer)
    Cancel = True
    Effect = 1
    ListBox2.AddItem Data.GetText
End Sub

Private Sub ListBox1_MouseMove(ByVal Button As Integer, ByVal Shift _
        As Integer, ByVal X As Single, ByVal Y As Single)
    Dim MyDataObject As DataObject
    If Button = 1 Then
        Set MyDataObject = New DataObject
        Dim Effect As Integer
        MyDataObject.SetText ListBox1.Value
        Effect = MyDataObject.StartDrag
    End If
End Sub

Private Sub UserForm_Initialize()
    For i = 1 To 10
        ListBox1.AddItem "Choice " & (ListBox1.ListCount + 1)
    Next i
End Sub