Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
645
Dragging first row of grid scrolls the whole grid
posted

Hi,

I'm having problem with dragging and dropping with UltraWinGrid. This works great except when I drag and drop the first row of the grid. The grid keeps scrolling so that the dragged row is placed on top of ActiveRowScrollRegion. Do the same action with other rows and it works fine. Could you please point out the problem so that a solution can be found for this issue? Thanks a lot. I post my code below for reference.

 

private void gridWork_DragDrop(object sender, DragEventArgs e)
        {
            int dropIndex = 0;
            UIElement uieOver = gridWork.DisplayLayout.UIElement.ElementFromPoint(gridWork.PointToClient(new Point(e.X, e.Y)));

            UltraGridRow ugrOver = uieOver.GetContext(typeof(UltraGridRow), true) as UltraGridRow;
            if (ugrOver != null)
            {
                dropIndex = ugrOver.Index;
            }

            if (dropIndex < 0)
            {
                dropIndex = gridWork.Rows.Count;
            }

            if (dropIndex >= 0)
            {
                gridWork.Selected.Rows.Sort();

                for (int i = gridWork.Selected.Rows.Count - 1; i > -1; i--)
                {
                    if (gridWork.Selected.Rows[i].Index < dropIndex)
                    {
                        dropIndex -= 1;
                    }
                    gridWork.Rows.Move(gridWork.Selected.Rows[i], dropIndex);
                }
            }
        }

 

private void gridWork_DragOver(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Move;
            UltraGrid grid = sender as UltraGrid;
            Point pointInGridCoords = grid.PointToClient(new Point(e.X, e.Y));
            if (pointInGridCoords.Y < 20)
            {
                this.gridWork.ActiveRowScrollRegion.Scroll(RowScrollAction.LineUp);
            }
            else if (pointInGridCoords.Y > grid.Height - 20)
            {
                this.gridWork.ActiveRowScrollRegion.Scroll(RowScrollAction.LineDown);
            }
        }

 

private void gridWork_SelectionDrag(object sender, CancelEventArgs e)
        {
            gridWork.DoDragDrop(gridWork.Selected.Rows, DragDropEffects.Move);
        }

Parents
No Data
Reply
  • 469350
    Suggested Answer
    Offline posted

    Hi,

    I'm not sure I understand what you are asking. The grid doesn't have any built-in functionality to drag and drop rows. Nor does it automatically scroll vertically during a drag operation. So if the grid is scrolling too far, something in your code is doing that.

    I don't see anything in your code here that would be any different for the first row than any other row in the grid. But I am not really sure what you are describing or exactly what the issue is.

    I tried the code you posted here and dragged a few rows around, but I don't see any difference between the first row or any other row.

Children
No Data