zoukankan      html  css  js  c++  java
  • C# Devexpress 中GridControl多行数据拖拽(转)

    using DevExpress.XtraGrid.Views.Grid.ViewInfo;
    using DevExpress.XtraGrid;

    // 声明:

     private GridHitInfo downHitInfo;

    设置多行选中

     GridView1.OptionsSelection.MultiSelect = true;

    //事件处理:

    //要拖动的数据

      private void GridControl1_MouseDown(object sender, MouseEventArgs e)
            {
                downHitInfo = GridView1.CalcHitInfo(new Point(e.X, e.Y));
            }

            private void GridControl1_MouseMove(object sender, MouseEventArgs e)
            {
                if (downHitInfo == null) return;
                if (e.Button != MouseButtons.Left) return;
                Rectangle dragRect = new Rectangle(new Point(
                    downHitInfo.HitPoint.X - SystemInformation.DragSize.Width / 2,
                    downHitInfo.HitPoint.Y - SystemInformation.DragSize.Height / 2), SystemInformation.DragSize);
                if (!dragRect.Contains(new Point(e.X, e.Y)))
                {
                    DataRow data = GridView1.GetDataRow(downHitInfo.RowHandle);
                    int[] rows = GridView1.GetSelectedRows();
                    List<DataRow> row = new List<DataRow>();
                    for (int i = 0; i < rows.Length; i++)
                        row.Add(GridView1.GetDataRow((int)rows[i]));
                    GridControl1.DoDragDrop(row, DragDropEffects.Copy);
                }
            }

    //要存放的GridControl

    // 设置为可接受拖拽数据 

     GridControl2.AllowDrop = true;

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

            private void GridControl2_DragDrop(object sender, DragEventArgs e)
            {
                GridControl grid = sender as GridControl;
                DataTable table = grid.DataSource as DataTable;
                List<DataRow> row = e.Data.GetData(typeof(List<DataRow>)) as List<DataRow>;
                if (row != null && table != null)
                {
                    if (row.Count > 0)
                    {
                        for (int i = 0; i < row.Count; i++)
                        {
                            table.ImportRow(row[i]);
                            row[i].Delete();  // 把原有的数据行删除。
                        }
                    }
                }
            }


    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Fing_king/archive/2010/08/01/5781591.aspx

  • 相关阅读:
    webpack2 前篇
    vue 的调试工具
    CSS 命名规范总结
    reset.css
    推荐几个精致的web UI框架
    自己是个菜鸟 自己查找的简单的适合初学的Makefile
    Linux下编译、使用静态库和动态库 自己测过的
    函数参数的传递 动态内存传递问题(指针的指针)
    二级指针 (C语言)
    find_if查找vector内对象的成员 作为菜鸟一直不会用也不敢用
  • 原文地址:https://www.cnblogs.com/linyijia/p/1912443.html
Copyright © 2011-2022 走看看