none
[C#]I want to drag-and-drop between rows on a single gridcontrol view in Dev Express. RRS feed

  • Question

  • 1. I created a view and made the bound data appear in the view through the package call.
    2. I want to rearrange the rows of data in the view.
    ex) value -> value
             up       up
          down     left
            left     down
          right      right
    3. Now, as I expected, I think dragging is not going through the rows. I've tried drag and drop in the behavior manager, but I can not help it.

    gridcontrol->grdProgramStdInfo ,,gridview->grvProgramStdInfo ! 

    GridHitInfo downHitInfo = null;
    
            private void gridControl_MouseDown(object sender, MouseEventArgs e)
    
            {
                GridView view = sender as GridView;
    
                downHitInfo = null;
    
                GridHitInfo hitInfo = view.CalcHitInfo(new Point(e.X, e.Y));
    
                if (Control.ModifierKeys != Keys.None) return;
    
                if (e.Button == MouseButtons.Left && hitInfo.RowHandle >= 0)
    
                    downHitInfo = hitInfo;
            }
            private void gridControl_MouseMove(object sender, MouseEventArgs e)
    
            {
                GridView view = sender as GridView;
    
                if (e.Button == MouseButtons.Left && downHitInfo != null)
                {
    
                    Size dragSize = SystemInformation.DragSize;
    
                    Rectangle dragRect = new Rectangle(new Point(downHitInfo.HitPoint.X - dragSize.Width / 2,
    
                        downHitInfo.HitPoint.Y - dragSize.Height / 2), dragSize);
    
    
    
                    if (!dragRect.Contains(new Point(e.X, e.Y)))
                    {
    
                        DataRow row = view.GetDataRow(downHitInfo.RowHandle);
    
                        view.GridControl.DoDragDrop(row, DragDropEffects.Move);
    
                        downHitInfo = null;
    
                        DevExpress.Utils.DXMouseEventArgs.GetMouseArgs(e).Handled = true;
    
                    }
    
                }
            }
            private void gridControl_DragOver(object sender, DragEventArgs e)
    
            {
                if (e.Data.GetDataPresent(typeof(DataRow)))
    
                    e.Effect = DragDropEffects.Move;
    
                else
    
                    e.Effect = DragDropEffects.None;
            }
            private void gridControl_DragDrop(object sender, DragEventArgs e)
    
            {
                GridControl grid = sender as GridControl;
    
                DataTable table = grid.DataSource as DataTable;
    
                DataRow row = e.Data.GetData(typeof(DataRow)) as DataRow;
    
                if (row != null && table != null && row.Table != table)
                {
    
                    table.ImportRow(row);
    
                    row.Delete();
    
                }
            }
    private void dragDropEvents1_DragDrop(object sender, DragDropEventArgs e)
            {
                
            }
            private void dragDropEvents1_DragOver(object sender, DragOverEventArgs e)
            {
                DragOverGridEventArgs args = DragOverGridEventArgs.GetDragOverGridEventArgs(e);
                e.InsertType = args.InsertType;
                e.InsertIndicatorLocation = args.InsertIndicatorLocation;
                e.Action = args.Action;
                Cursor.Current = args.Cursor;
                args.Handled = true;
            }
    
    this.grdProgramStdInfo.DragDrop += new System.Windows.Forms.DragEventHandler(this.gridControl_DragDrop);
                this.grdProgramStdInfo.DragOver += new System.Windows.Forms.DragEventHandler(this.gridControl_DragOver);
    this.grvProgramStdInfo.MouseDown += new System.Windows.Forms.MouseEventHandler(this.gridControl_MouseDown);
                this.grvProgramStdInfo.MouseMove += new System.Windows.Forms.MouseEventHandler(this.gridControl_MouseMove

    • Moved by CoolDadTx Tuesday, July 16, 2019 1:47 PM Third party product
    Tuesday, July 16, 2019 10:42 AM

All replies

  • Hello,

    You should be using DevExpress support.

    https://www.devexpress.com/Support/Center/


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, July 16, 2019 11:03 AM