drag column to group

5 posts, 0 answers
  1. Claude
    Claude avatar
    39 posts
    Member since:
    Jun 2020

    Posted 14 Jan Link to this post

    I can no longer drag a column header to the group by box at the top.  Not sure when this stopped working.  When I click on the column header it is highlighted, but I can not drag it.   Does it have something to do with the drag and drop of rows I added to my app. I am using your provided service for the row drag and drop.  I believe I have everything enabled.

     

                    dgvFiles.ShowGroupPanel = true;
                    this.dgvFiles.AllowSearchRow = true;
                    dgvFiles.Columns[1].AllowGroup = false;  // prevent grouping of Path Column
                    dgvFiles.Columns[2].AllowGroup = true;//filename
                    dgvFiles.Columns[3].AllowGroup = true;// length
                    dgvFiles.Columns[4].AllowGroup = true; // catagory

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4177 posts

    Posted 18 Jan Link to this post

    Hello, Claude, 

    According to the provided information, it seems that you have custom implementation for the drag and drop behavior. I suppose that you are using the approach demonstrated here: https://docs.telerik.com/devtools/winforms/controls/gridview/rows/drag-and-drop 

    If the grouping is enabled on your end, you need to do 2 small modifications in the code to keep the default grouping functionality. The RadDragDropService's PreviewDragOver and PreviewDragDrop events are illustrated below:
            private void svc_PreviewDragOver(object sender, RadDragOverEventArgs e)
            {
                if (e.DragInstance is GridDataRowElement)
                {
                    Console.WriteLine(e.HitTarget);
                    e.CanDrop = e.HitTarget is GridDataRowElement ||
                                e.HitTarget is GridTableElement ||
                                e.HitTarget is GridSummaryRowElement ||
                                e.HitTarget is GroupPanelElement;
                }
            }
    
            private void svc_PreviewDragDrop(object sender, RadDropEventArgs e)
            {
                var rowElement = e.DragInstance as GridDataRowElement;
                if (rowElement == null)
                {
                    return;
                }
                if (e.HitTarget is GroupPanelElement)
                {
                    e.Handled = false;
                }
                else
                {
                    e.Handled = true;
    
                    var dropTarget = e.HitTarget as RadItem;
                    var targetGrid = dropTarget.ElementTree.Control as RadGridView;
                    if (targetGrid == null)
                    {
                        return;
                    }
    
                    var dragGrid = rowElement.ElementTree.Control as RadGridView;
                    if (targetGrid != dragGrid)
                    {
                        e.Handled = true;
                        //append dragged rows to the end of the target grid
                        int index = targetGrid.RowCount;
    
                        //Grab every selected row from the source grid, including the current row
                        List<GridViewRowInfo> rows =
                            dragGrid.SelectedRows.ToList<GridViewRowInfo>();
                        if (dragGrid.CurrentRow != null)
                        {
                            GridViewRowInfo row = dragGrid.CurrentRow;
                            if (!rows.Contains(row))
                                rows.Add(row);
                        }
                        this.MoveRows(targetGrid, dragGrid, rows, index);
                    }
                }
            }
    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

  3. Claude
    Claude avatar
    39 posts
    Member since:
    Jun 2020

    Posted 18 Jan in reply to Dess | Tech Support Engineer, Sr. Link to this post

    I have implemented these recommended changes, but I am still not able to drag a column to the group box at the top of the grid.  In fact, if the column header is selected neither of these methods are triggered.  
  4. Claude
    Claude avatar
    39 posts
    Member since:
    Jun 2020

    Posted 18 Jan in reply to Claude Link to this post

    If I change the e.CanStart from false to true all worked fine

    else
                {
                    e.CanStart = true;
                }

     

    private void svc_PreviewDragStart(object sender, PreviewDragStartEventArgs e)
            {

                GridDataRowElement draggedRowElement = e.DragInstance as GridDataRowElement;
                if (draggedRowElement != null && draggedRowElement.RowInfo != null)
                {
                    e.CanStart = true;
                    draggedRow = draggedRowElement.RowInfo;
                }
                else
                {
                    e.CanStart = true;
                }

  5. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4177 posts

    Posted 19 Jan Link to this post

    Hello, Claude, 

    The PreviewDragStart event of the RadGridViewDragDropService fires when the drag and drop operation is about to be started. In the PreviewDragStartEventArgs you have access to the DragInstance. You can control whether the service should be started or not for this element by the CanStart argument.

    According to the provided code snippet, you can leave only setting the CanStart argument to true. You don't need the if-else construction here if you are not going to restrict starting the drag operation. 

    Should you have further questions please let me know.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Back to Top