This documentation is archived and is not being maintained.

ItemDragEventArgs.Item Property

Gets the item that is being dragged.

[Visual Basic]
Public ReadOnly Property Item As Object
[C#]
public object Item {get;}
[C++]
public: __property Object* get_Item();
[JScript]
public function get Item() : Object;

Property Value

An object that represents the item being dragged.

Remarks

You can use this property to determine which item from the TreeView or ListView controls is being dragged from the control.

Example

[Visual Basic, C#, C++] The following example illustrates the use of ItemDragEventArgs when enabling drag-and-drop operations within a TreeView control. 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 that indicates the desired effect of the drag-and-drop operation.

[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 Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ItemDragEventArgs Class | ItemDragEventArgs Members | System.Windows.Forms Namespace

Show: