This is a migrated thread and some comments may be shown as answers.

drag column to group

4 Answers 219 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Claude
Top achievements
Rank 1
Iron
Veteran
Claude asked on 14 Jan 2021, 07:07 PM

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

4 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 18 Jan 2021, 10:20 AM
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/.

0
Claude
Top achievements
Rank 1
Iron
Veteran
answered on 18 Jan 2021, 05:18 PM
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.  
0
Claude
Top achievements
Rank 1
Iron
Veteran
answered on 18 Jan 2021, 05:55 PM

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;
            }

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Jan 2021, 06:52 AM
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/.

Tags
GridView
Asked by
Claude
Top achievements
Rank 1
Iron
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Claude
Top achievements
Rank 1
Iron
Veteran
Share this question
or