Skip to content

ListView (Details) Drag Drop #913

Closed
Closed

Description

@itg-assistant

conrad asked 2017-06-21 23:15:27 UTC

Am I missing something here? I'm trying to "drag" from ListView2 and "drop" to ListView1

private void Window1_Load(object sender, EventArgs e)
{
listView1.AllowDrop = true;
listView1.DragDrop += new DragEventHandler(listView1_DragDrop);
listView1.DragEnter += new DragEventHandler(listView1_DragEnter);
}

private void listView1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}

private void listView1_DragDrop(object sender, DragEventArgs e)
{
listView1.Items.Add(e.Data.ToString());
}

Activity

  1. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2017-06-21 23:58:55 UTC

    To drag from listView2:

    listView2.AllowDrag = true;

    listView2.DragStart += listView2_DragStart;

    private void listView2_DragStart(object sender, EventArgs e)
    {
    var listView = (ListView)sender;
    var items = listView.SelectedItems.ToArray();
    if (items.Length > 0)
    {
    listView.DoDragDrop(items, DragDropEffects.Move);
    }
    }

    You can adapt this part in many ways. The call to DoDragDrop() saves the data to drag and drop and specified which effect is allowed.

    The sample above will start dragging only if there is one or more item selected. The ListView class has an event ItemDrag that is not implemented yet, but DragStart works for all controls in Wisej and you can decide how and what to drag.

    Then to drop into listView1, or into anything else actually:

    listView1.AllowDrop = true;

    listView1.DragEnter += listView1.DragEnter;

    listView1.DragDrop += listView1.DragDrop;

    private void ListView1_DragEnter(object sender, DragEventArgs e)
    {

         // here you can check the allowed effects specified in e decide what to respond. you can cancel drag or select the effect you want.
    e.Effect = DragDropEffects.Move;
    }

    private void ListView1_DragDrop(object sender, DragEventArgs e)
    {

        // here you can handle whatever data is being dragged and dropped.

       // in this case we saved an array of ListViewItem, but it can be anything.

       // and can decide if to move the items, clone them, change them, log, etc.

    var items = (ListViewItem[])e.Data.GetData(typeof(ListViewItem[]));
    if (items != null)
    {
    var listView = (ListView)sender;
    foreach (var item in items)
    {
    item.Remove();
    listView.Items.Add(item);
    }
    }
    }

    HTH

    /Luca

  2. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    conrad answered 2017-06-22 15:26:07 UTC

    worked like a charm. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GeneralQuestions, how-tos and everything else.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions