通过


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 属性确定拖动的节点是应移动还是复制到其目标。 然后,由属性表示ItemDoDragDrop节点连同指示拖放操作所需效果的值一TreeView起传递给控件的方法。

有关完整示例,请参阅 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

注解

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

适用于