ItemDragEventArgs Class
Provides data for the ItemDrag event of the ListView and TreeView controls.
For a list of all members of this type, see ItemDragEventArgs Members.
System.Object
System.EventArgs
System.Windows.Forms.ItemDragEventArgs
[Visual Basic] <ComVisible(True)> Public Class ItemDragEventArgs Inherits EventArgs [C#] [ComVisible(true)] public class ItemDragEventArgs : EventArgs [C++] [ComVisible(true)] public __gc class ItemDragEventArgs : public EventArgs [JScript] public ComVisible(true) class ItemDragEventArgs extends EventArgs
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
The ItemDrag event occurs when the user begins dragging an item. An ItemDragEventArgs object specifies which mouse button was pressed.
Example
[Visual Basic, C#, C++] 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 System.Windows.Forms.TreeView.DoDragDrop method along with a value indicating the desired effect.
[Visual Basic, C#, C++] For the complete example, see the TreeView.ItemDrag reference topic.
[Visual Basic] Private Sub treeView1_ItemDrag(ByVal sender As Object, ByVal e As ItemDragEventArgs) ' Move the dragged node when the left mouse button is used. If e.Button = MouseButtons.Left Then DoDragDrop(e.Item, DragDropEffects.Move) ' Copy the dragged node when the right mouse button is used. ElseIf e.Button = MouseButtons.Right Then DoDragDrop(e.Item, DragDropEffects.Copy) End If End Sub 'treeView1_ItemDrag [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); } } [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); } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Windows.Forms
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)