原創(chuàng)|使用教程|編輯:我只采一朵|2014-06-11 09:46:16.000|閱讀 5925 次
概述:本篇將介紹如何把一個(gè)DevExpress treelist的節(jié)點(diǎn)用鼠標(biāo)拖到另外的節(jié)點(diǎn)(自身或其他的listview)
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
本篇要實(shí)現(xiàn)的目標(biāo),簡(jiǎn)單來(lái)說(shuō)就是把一個(gè)DevExpress treelist的節(jié)點(diǎn)用鼠標(biāo)拖到另外的節(jié)點(diǎn)(自身或其他的listview)上,如下圖:
首先,在窗口中拉入兩個(gè)listview,第一個(gè)創(chuàng)建三列(上),第二個(gè)創(chuàng)建兩列(下),如下圖:
為第一個(gè)listview創(chuàng)建一些節(jié)點(diǎn):
定義一個(gè)取得拖拽對(duì)象中節(jié)點(diǎn)的方法:
private TreeListNode GetDragNode(IDataObject data) { return (TreeListNode)data.GetData(typeof(TreeListNode)); }
在兩個(gè)treelist中同時(shí)定義DragDrop(鼠標(biāo)松開(kāi))和DragEnter(開(kāi)始拖拽)事件:
private void treeList1_DragDrop(object sender, DragEventArgs e) { TreeListNode node = GetDragNode(e.Data); if (node == null) return; TreeList list = (TreeList)sender; if (list == node.TreeList) return; TreeListHitInfo info = list.CalcHitInfo(list.PointToClient(new Point(e.X, e.Y))); InsertBrush(list,node,info.Node==null?-1:info.Node.Id); } private void treeList1_DragEnter(object sender, DragEventArgs e) { TreeList list = (TreeList)sender; TreeListNode node = GetDragNode(e.Data); if (node != null && node.TreeList != list) e.Effect = DragDropEffects.Copy; }
最后定義插入節(jié)點(diǎn)的方法:
private void InsertBrush(TreeList list, TreeListNode node, int parent) { ArrayList data = new ArrayList(); foreach (TreeListColumn column in node.TreeList.Columns) { data.Add(node[column]); } parent = list.AppendNode(data.ToArray(), parent).Id; if (node.HasChildren) foreach (TreeListNode n in node.Nodes) InsertBrush(list, n, parent); }
現(xiàn)在就可以用鼠標(biāo)實(shí)現(xiàn)兩個(gè)列表的互拖了:
擴(kuò)展閱讀:
DevExpress 2014.1強(qiáng)勢(shì)來(lái)襲,歡迎下載體驗(yàn)!
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn