dev TreeList拖拽

dev TreeList拖拽

一、说明

使用dev控件,TreeList1向TreeList2拖拽

二、属性

            //允许拖拽
            treeList1.AllowDrop = true;
            treeList2.AllowDrop = true;
            //允许多行选择
            treeList1.OptionsSelection.MultiSelect = true;

三、代码

        #region tree拖拽操作

        TreeListHitInfo downHitInfo = null;
        #region 拖出
        private void treeList1_MouseMove(object sender, MouseEventArgs e)
        {
            TreeList treelist = sender as TreeList;
            if (e.Button == MouseButtons.Left && downHitInfo != null)
            {
                if (treeList1.Selection.Count == 0)
                    return;
                Size dragSize = SystemInformation.DragSize;
                Rectangle dragRect = new Rectangle(new Point(downHitInfo.MousePoint.X - dragSize.Width / 2,
                    downHitInfo.MousePoint.Y - dragSize.Height / 2), dragSize);

                if (!dragRect.Contains(new Point(e.X, e.Y)))
                {
                    List<TreeListNode> node = new List<TreeListNode>();
                    foreach (TreeListNode n in treeList1.Selection)
                    {
                        node.Add(n);
                    }
                    treelist.DoDragDrop(downHitInfo.Node, DragDropEffects.Move);
                    downHitInfo = null;
                    DevExpress.Utils.DXMouseEventArgs.GetMouseArgs(e).Handled = true;
                }
            }
            
        }


        private void treeList1_MouseDown(object sender, MouseEventArgs e)
        {
            TreeList treelist = sender as TreeList;
            downHitInfo = null;
            TreeListHitInfo hitInfo = treelist.CalcHitInfo(new Point(e.X, e.Y));

            if (Control.ModifierKeys != Keys.None) return;
            if (e.Button == MouseButtons.Left)
            {
                downHitInfo = hitInfo;
            }
        }

        #endregion

        #region 拖入
        private void treeList2_DragOver(object sender, DragEventArgs e)
        {
            TreeList treelist = sender as TreeList;
            if (treelist != null)
            {
                e.Effect = DragDropEffects.Move;
            }
        }



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

        private void treeList2_DragDrop(object sender, DragEventArgs e)
        {
            List<TreeListNode> nodes = e.Data.GetData(typeof(List<TreeListNode>)) as List<TreeListNode>;
            TreeList grid = sender as TreeList;
            DataTable table = grid.DataSource as DataTable;

            if (nodes != null && nodes.Count > 0 && table != null)
            {
                foreach (TreeListNode node in nodes)
                {
                    treeList1.Nodes.Add(node);
                }
            }
        }
        #endregion
        #endregion

原文:http://www.cnblogs.com/hhl-kf/p/TreeList_AllowDrop.html

转载于:https://www.cnblogs.com/1175429393wljblog/p/7261771.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值