拖放多个项从一个列表框移到另一个列表框. [英] Drag and Drop mutliple items form one listbox to another.

查看:58
本文介绍了拖放多个项从一个列表框移到另一个列表框.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

有谁能建议我一种使用C#在Windows窗体应用程序中实现将多个项目从一个列表框拖放到另一个列表中的方法.我可以为单个项目实现两个列表框之间的拖放,但是却被多个项目实现所打击...

感谢Advance

Hi All,

Can any one suggest me a way to implemt dragging and dropping multiple items from one listbox to another in windows forms application using C#. I am able to implement drag and drop between two listboxes for a single item but got struck with multiple items implementation...

Thanks in Advance

推荐答案



在此示例中,我假设您要拖动&的列表视图中有人"列表.

启动拖放操作.放在来源"例如这样的listview面:

Hi,

In this example I assume that you have list of Persons in the listviews you want to drag & drop between source and target listviews.

Initiate the drag & drop on the "source" listview side like this for example:

私有 void listViewSource_ItemDrag( 对象 发件人,ItemDragEventArgs e)
{
font style ="color:blue">如果 ( this .listViewSource.SelectedIndices.Coun t> 0)
{{
List< Person> selectedPersons = List< Person>();
foreach <字体样式="font-size:11px">( int 索引 输入 selectedPersons.Add(.sourceList [index]);
}
font style ="color:blue">此 .listViewSource.DoDragDrop(selectedPersons,DragDropEffects.Copy || DragDropEffects.Move);
}
private void listViewSource_ItemDrag(object sender, ItemDragEventArgs e) 
        { 
            if (this.listViewSource.SelectedIndices.Count > 0) 
            { 
                List<Person> selectedPersons = new List<Person>(); 
                foreach (int index in this.listViewSource.SelectedIndices) 
                { 
                    selectedPersons.Add(this.sourceList[index]); 
                } 
                this.listViewSource.DoDragDrop(selectedPersons, DragDropEffects.Copy | DragDropEffects.Move); 
            } 
        } 


这篇关于拖放多个项从一个列表框移到另一个列表框.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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