• C# listview 拖动节点


    /// <summary>
            /// 当拖动某项时触发
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
            {
                listView1.DoDragDrop(e.Item, DragDropEffects.Move);
            }
    
            /// <summary>
            /// 鼠标拖动某项至该控件的区域
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void listView1_DragEnter(object sender, DragEventArgs e)
            {
                e.Effect = DragDropEffects.Move;
            }
    
            /// <summary>
            /// 拖动时拖着某项置于某行上方时
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void listView1_DragOver(object sender, DragEventArgs e)
            {
                Point ptScreen = new Point(e.X, e.Y);
                Point pt = listView1.PointToClient(ptScreen);
                ListViewItem item = listView1.GetItemAt(pt.X, pt.Y);
                if (item != null)
                    item.Selected = true;
            }
    
            /// <summary>
            /// 结束拖动
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void listView1_DragDrop(object sender, DragEventArgs e)
            {
                ListViewItem draggedItem = (ListViewItem)e.Data.GetData(typeof(ListViewItem));//旧目标
                Point ptScreen = new Point(e.X, e.Y);
                Point pt = listView1.PointToClient(ptScreen);
                ListViewItem TargetItem = listView1.GetItemAt(pt.X, pt.Y);//新目标   
                if (null == TargetItem)
                {
                    return;
                }
                if (MessageBoxEx.Show("[" + draggedItem.Text + "]转至[" + TargetItem.Text + "]", "询问", 
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    var item = draggedItem.Tag as View_TableListModel;
                    int tableid = item.ID;
                    
                }
                //listView1.Items.Insert(TargetItem.Index, (ListViewItem)draggedItem.Clone());
                //listView1.Items.Remove(draggedItem);
            }
  • 相关阅读:
    关于技术的学习及批判 人工智能
    爱迪生如何看待手机程序员怎么用移动互联网 人工智能
    量子学习及思考4群体意识 人工智能
    程序员的出路 人工智能
    函数式编程学习之路(14) 人工智能
    量子学习及思考1开篇 人工智能
    函数式编程学习之路(16)图灵完备 人工智能
    开机启动
    动态连接库
    静态常量的问题
  • 原文地址:https://www.cnblogs.com/starksoft/p/3944722.html
Copyright © 2020-2023  润新知