Winform ListView 元素拖动

//ListView 属性
        /* AllowDrop : True */

        ListView objLVDrag;
        private void listView_DragDrop(object sender, DragEventArgs e)
        {
            //获取拖动的数据项创建数组
            ListView.SelectedListViewItemCollection items = e.Data.GetData("wjshan0808") as ListView.SelectedListViewItemCollection;
            foreach (ListViewItem item in items)
            {
                //向目的空间中添加
                ((ListView)(sender)).Items.Add(item.Text);
                //从源控件中移除
                objLVDrag.Items.Remove(objLVDrag.SelectedItems[0]);
            }
        }
        private void listView_ItemDrag(object sender, ItemDragEventArgs e)
        {
            // System.Windows.Forms.DataFormats 
            objLVDrag = sender as ListView;
            //自定义DataFormats的拖动数据格式
            objLVDrag.DoDragDrop(new DataObject("wjshan0808", objLVDrag.SelectedItems), DragDropEffects.Move);
        }
        private void listView_DragEnter(object sender, DragEventArgs e)
        {
            //检测自定义的DataFormat ListView数组
            if (e.Data.GetDataPresent("wjshan0808"))
                e.Effect = DragDropEffects.Move;//移动数据
            else
                e.Effect = DragDropEffects.None;
        }

 

Winform ListView 元素拖动

上一篇:POJ 2823 Sliding Window (滑动窗口的最值问题 )


下一篇:oschina openapi php 调用