ItemDragEventArgs.Item 属性

定义

获取正被拖动的项。

public:
 property System::Object ^ Item { System::Object ^ get(); };
public object Item { get; }
public object? Item { get; }
member this.Item : obj
Public ReadOnly Property Item As Object

属性值

表示正被拖动的项的对象。

示例

以下示例演示在控件中TreeView启用拖放操作时如何使用 ItemDragEventArgs 。 属性 Button 确定是应移动还是应将拖动的节点复制到其目标。 然后,由 Item 属性表示的节点连同指示拖放操作所需效果的值一起传递到 TreeView 控件 DoDragDrop 的 方法。

有关完整示例,请参阅 TreeView.ItemDrag 参考主题。

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
      
      // Copy the dragged node when the right mouse button is used.
      if ( e->Button == ::MouseButtons::Right )
      {
         DoDragDrop( e->Item, DragDropEffects::Copy );
      }
   }
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);
    }
}
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

注解

可以使用此属性来确定从 TreeView 控件拖动 或 ListView 控件中的哪个项。

适用于