Edit

Share via


ItemDragEventArgs Class

Definition

Provides data for the ItemDrag event of the ListView and TreeView controls.

C#
[System.Runtime.InteropServices.ComVisible(true)]
public class ItemDragEventArgs : EventArgs
C#
public class ItemDragEventArgs : EventArgs
Inheritance
ItemDragEventArgs
Attributes

Examples

The following example illustrates the use of ItemDragEventArgs when enabling drag-and-drop operations within a TreeView. The Button property determines whether the dragged node should be moved or copied to its destination. The node, represented by the Item property, is then passed to the TreeView control's DoDragDrop method along with a value indicating the desired effect.

For the complete example, see the TreeView.ItemDrag reference topic.

C#
private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
{
    // Move the dragged node when the left mouse button is used.
    if (e.Button == MouseButtons.Left)
    {
        DoDragDrop(e.Item, DragDropEffects.Move);
    }

    // Copy the dragged node when the right mouse button is used.
    else if (e.Button == MouseButtons.Right)
    {
        DoDragDrop(e.Item, DragDropEffects.Copy);
    }
}

Remarks

The ItemDrag event occurs when the user begins dragging an item. An ItemDragEventArgs object specifies which mouse button was pressed.

Constructors

ItemDragEventArgs(MouseButtons, Object)

Initializes a new instance of the ItemDragEventArgs class with a specified mouse button and the item that is being dragged.

ItemDragEventArgs(MouseButtons)

Initializes a new instance of the ItemDragEventArgs class with a specified mouse button.

Properties

Button

Gets a value that indicates which mouse buttons were pressed during the drag operation.

Item

Gets the item that is being dragged.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9