Drag and drop listview C#

前端 未结 1 1850
北荒
北荒 2021-01-17 05:44

Hi how to I enable drag event handler when I double click on the listview?

This is what I get after double-clicking on the listview

private void list         


        
相关标签:
1条回答
  • 2021-01-17 06:14

    You need to implement the DragEnter event and set the Effect property of the DragEventArgs. The DragEnter event is what allows things to be dropped into a control. After that the DragDrop event will fire when the mouse button is released.

    Here is a version that will allow objects to be dropped into the a ListView:

        private void Form1_Load(object sender, EventArgs e)
        {
            listView1.AllowDrop = true;
            listView1.DragDrop += new DragEventHandler(listView1_DragDrop);
            listView1.DragEnter += new DragEventHandler(listView1_DragEnter);
        }
    
        void listView1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
        }
    
        void listView1_DragDrop(object sender, DragEventArgs e)
        {
            listView1.Items.Add(e.Data.ToString());
        }
    

    No doubt your sample code was taken from : http://msdn.microsoft.com/en-us/library/system.windows.forms.control.allowdrop(v=vs.71).aspx

    0 讨论(0)
提交回复
热议问题