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

Hierarchy/DragDrop: Childrows are not updated

1 Answer 32 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 06 May 2019, 01:32 PM

Hello,

Again a problem regarding the hierarchy mode of the RadGridView. Datasource is a hierarchy object with multiple levels (based on BindingList).

  1. If the childrows are expanded and then the row is moved (in this case via drag & drop, but the actual move done via the list) and the row is expanded again, the childrows are the rows of the old item. If the childrows are not expanded bevor the move operation they are displayed correctly)

    Sample project and screen recording is attached.
    (In the screen recording, after the move the child rows of "Item 1" should be "Item 1 - 1 - x" but they are "Item 1 - 2 - x")

  2. Also, in this mode the custom GridDataRowBehavior (as it's described in the examples) is not working, the OnMouseDownLeft is never called. Is this a bug or is it an expected behavior?

Kind regards,

Christian

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 May 2019, 07:52 AM
Hello, Christian,     

The provided sample project and gif file are greatly appreciated. 

1. If you generate the hierarchy automatically, note that you should notify the grid fr the inner level's changes after the drag-drop operation. One possible solution is to rebind the grid in the PreviewDragDrop event in order to force rebuilding the automatically generated hierarchy which has been cached once the row is expanded. Alternatively, you can simply refresh all of the templates:

private void svc_PreviewDragDrop(object sender, RadDropEventArgs e)
{
    var rowElement = e.DragInstance as SnapshotDragItem;
    if (rowElement == null)
    {
        return;
    }
    e.Handled = true;
 
    var dropTarget = e.HitTarget as GridDataRowElement;
    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 = dropTarget.Parent.Children.IndexOf(dropTarget);
 
        //Grab every selected row from the source grid, including the current row
        List<GridViewRowInfo> rows = dragGrid.SelectedRows.ToList<GridViewRowInfo>();
        this.MoveRows(targetGrid, dragGrid, rows, index);
    }
 
    targetGrid.MasterTemplate.Refresh();
    targetGrid.MasterTemplate.Templates[0].Refresh();
    targetGrid.MasterTemplate.Templates[0].Templates[0].Refresh();
}

I would recommend you to have a look at the following KB article demonstrating how to achieved CRUD operations in an object-relational hierarchy in RadGridViewhttps://www.telerik.com/support/kb/winforms/gridview/details/radgridview-crud-in-object-relational-hierarchy-mode

2. RadGridView manages user mouse and keyboard input over its rows by GridRowBehavior. Depending on the row type, RadGridView introduces different behaviors. After investigating the code in the sample project I have noticed that you register a custom GridDataRowBehavior for the GridViewDataRowInfo. When you have a hierarchical grid, note that you should implement a custom GridHierarchyRowBehavior for the GridViewHierarchyRowInfos as well. A full list of all row behaviors is available in the following help article: https://docs.telerik.com/devtools/winforms/controls/gridview/rows/row-behaviors

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
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Christian
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or