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

備註

您可以使用這個屬性來判斷從 控制項拖曳或 ListView 控制項中的 TreeView 專案。

適用於