.NET Framework Class Library
DragDrop..::.DoDragDrop Method

Initiates a drag-and-drop operation.

Namespace:  System.Windows
Assembly:  PresentationCore (in PresentationCore.dll)
Syntax

Visual Basic (Declaration)
Public Shared Function DoDragDrop ( _
    dragSource As DependencyObject, _
    data As Object, _
    allowedEffects As DragDropEffects _
) As DragDropEffects
Visual Basic (Usage)
Dim dragSource As DependencyObject
Dim data As Object
Dim allowedEffects As DragDropEffects
Dim returnValue As DragDropEffects

returnValue = DragDrop.DoDragDrop(dragSource, _
    data, allowedEffects)
C#
public static DragDropEffects DoDragDrop(
    DependencyObject dragSource,
    Object data,
    DragDropEffects allowedEffects
)
Visual C++
public:
static DragDropEffects DoDragDrop(
    DependencyObject^ dragSource, 
    Object^ data, 
    DragDropEffects allowedEffects
)
JScript
public static function DoDragDrop(
    dragSource : DependencyObject, 
    data : Object, 
    allowedEffects : DragDropEffects
) : DragDropEffects
XAML
You cannot use methods in XAML.

Parameters

dragSource
Type: System.Windows..::.DependencyObject
A reference to the dependency object that is the source of the data being dragged.
data
Type: System..::.Object
A data object that contains the data being dragged.
allowedEffects
Type: System.Windows..::.DragDropEffects
One of the DragDropEffects values that specifies permitted effects of the drag-and-drop operation.

Return Value

Type: System.Windows..::.DragDropEffects
One of the DragDropEffects values that specifies the final effect that was performed during the drag-and-drop operation.
Exceptions

ExceptionCondition
ArgumentNullException

dragSource or data is nullNothingnullptra null reference (Nothing in Visual Basic).

Examples

The following example demonstrates how to use the DoDragDrop method.

Visual Basic
Private Sub DragStarted()
    m_IsDown = False

    Dim serializedObject As String = m_OriginalElement.OuterXml
    Dim data As DataObject = New DataObject()
    data.SetData(m_MyFormat.Name, serializedObject)
    Dim effects As DragDropEffects = _
        DragDrop.DoDragDrop(MyCanvas, data, DragDropEffects.Copy Or DragDropEffects.Move)
    If effects And DragDropEffects.Move Then
        ' Remove the element.
        m_OriginalElement.ParentNode.RemoveChild(m_OriginalElement)
        m_OriginalElement = Nothing
    End If
End Sub
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Tags :


Community Content

Rashad Rivera
Need more

Hello,

This page is not clear enough for people with little or no knowledge of "DragDrop.DoDragDrop" to understand. For example, why would I want to use this method. Why did both the Copy and Move enum(s) get used, but only the Move operation was used?

- Rashad Rivera

Tags :

Page view tracker