从listview拖放到dropConposition中的userControl [英] dragDrop from listview to userControl in drop location

查看:68
本文介绍了从listview拖放到dropConposition中的userControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为listView中的项目制作dragDrop以删除userControl中的位置

注意:我想在删除它后访问该项目及其属性

i know i应该把它作为对象删除,但我不知道如何!

解决方案

是的,使用标准技术可以检测到表面上任何类型的对象掉落一个UserControl,并且可以检测丢弃的对象的类型:

  private   void  YourUserControl1_DragDrop( object  sender,DragEventArgs e)
{
if (e.Data.GetFormats()。包含( System.Windows.Forms.ListViewItem))
{
ListViewItem droppedLVItem = e.Data.GetData( typeof (ListViewItem)) as ListViewItem的;
// 制作副本?
ListViewItem clonedItem =(ListViewItem)droppedLVItem。克隆();

// 现在是什么?
}
}

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

所以:假设您在UserControl中检测到位置100,200处的ListViewItem的丢弃,并且该位置没有可以吞下丢弃的控件(如另一个ListView):那个时候你想在UserControl中显示/创建什么?



ListViewItem 不是Control :你不能添加它到UserControl的Control Collection。



那么,你想做什么:构建一些新的用户界面对象,并将ListViewItem数据的一些表示放入或放在它上面?



或者,您是否希望使用ListViewItem的数据在UserControl的其他控件或数据结构中进行更改?



对解决方案进行投票,并在您得到满意的答案时选择一个可接受的解决方案,这是一种可以为CodeProject上的QA长期价值做出贡献的方法。


How can i make dragDrop for items fro listView to drop location in the userControl
note: i want to access the item and its properties after drop it
i know i should drop it as object but i dont know how!

解决方案

Yes, it's possible, using standard techniques, to detect a 'Drop of any type of Object on the surface of a UserControl, and it's possible to detect the Type of the Object dropped:

private void YourUserControl1_DragDrop(object sender, DragEventArgs e)
{
    if (e.Data.GetFormats().Contains("System.Windows.Forms.ListViewItem"))
    {
        ListViewItem droppedLVItem = e.Data.GetData(typeof (ListViewItem)) as ListViewItem;
        // make a copy ?
        ListViewItem clonedItem = (ListViewItem) droppedLVItem.Clone();

        // Now what ?
    }
}

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

So: let's say you detect a drop of a ListViewItem at position 100,200 in your UserControl, and there's no Control at that location that could "swallow" the drop (like another ListView): what do you want to show/create in the UserControl at that point ?

A ListViewItem is not a Control: you can't add it to the UserControl's Control Collection.

So, what do you want to do: construct some new user-interface object, and put some representation of the ListViewItem's data into, or on, it ?

Or, do you wish to use the ListViewItem's data to make changes in your UserControl's other Controls, or data-structures ?

Voting on solutons, and choosing an accepted solution when you get a response that answers your question to your complete satisfaction, is a way you can contribute to the long-run value of QA on CodeProject.


这篇关于从listview拖放到dropConposition中的userControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆