//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; }
时间: 2024-11-07 14:11:13