How to get old parent and new parent of a task after reordering(drag and drop) it?

5 posts, 2 answers
  1. Bahram
    Bahram avatar
    24 posts
    Member since:
    Feb 2019

    Posted 20 Mar 2019 Link to this post

    Hi there,

     

    Somehow I need to get old parent and new parent of a task after reordering it, but I can't find any event for that purpose. Can anyone help me with that please?

     

    Thanks,

    Developer1992

  2. Answer
    Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1180 posts

    Posted 22 Mar 2019 Link to this post

    Hi Bahram,

    I've prepared a small sample demonstrating how you can get the previous and new parent of a task by creating a custom GanttDragDropBehavior. Here's the code of interest:

    protected override void Drop(SchedulingDragDropState state)
    {
        var task = state.DraggedItem as GanttTask;
        var item = this.Gantt.ExpandCollapseService.HierarchicalCollectionAdapter.GetItemWrapperByItemKey(task);
        var previousParent = item.Parent;
        base.Drop(state);
        var newItem = this.Gantt.ExpandCollapseService.HierarchicalCollectionAdapter.GetItemWrapperByItemKey(task);
        var newParent = newItem.Parent;
    }

    Please note that I've used the GetItemWrapperByItemKey method to get ahold of the parents but you could alternatively iterate over the TasksSource collection and check each tasks' children.

    Please have a look and let me know whether such an approach would work for you.

    Regards,
    Dilyan Traykov
    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.
  3. Bahram
    Bahram avatar
    24 posts
    Member since:
    Feb 2019

    Posted 23 Mar 2019 in reply to Dilyan Traykov Link to this post

    Thank you so much Dilyan! That is definitely what I was looking for.

    There is one more thing that you may have a solution for, is there any event or any way that I can access to a task when I draw a relation from it to another(task)?

  4. Answer
    Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1180 posts

    Posted 25 Mar 2019 Link to this post

    Hi Bahram,

    I noticed that you opened a private support ticket with your new inquiry but so that it is beneficial to our community, I'm pasting my colleague's reply here as well:

    "In order to achieve what you are going for, you can set the DragDependenciesBehavior property of the RadGanttView to a custom behavior. The default class responsible for that is called GanttDragDependenciesBehavior and you can inherit from it. Here is some sample code:

    public class CustomDragDependenciesBehavior : GanttDragDependenciesBehavior
    {
        protected override void Link(SchedulingLinkState state)
        {
            base.Link(state);
        }
    }

    The virtual Link method is called when a connection is made between two tasks. You can also take a look at the other virtual methods to see, if any of them suit your needs better. 

    Of course, you need to make sure that the custom behavior is initialized as well:

    <telerik:RadGanttView x:Name="gantt"
                                         TasksSource="{Binding Tasks}">
                    <telerik:RadGanttView.DragDependenciesBehavior>
                          <local:CustomDragDependenciesBehavior />
                    </telerik:RadGanttView.DragDependenciesBehavior>
    </telerik:RadGanttView>

    The namespace "local" in the above snippet refers to the namespace where the "CustomDragDependenciesBehavior" class is defined."

    Regards,
    Dilyan Traykov
    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.
  5. Bahram
    Bahram avatar
    24 posts
    Member since:
    Feb 2019

    Posted 06 Apr 2019 in reply to Dilyan Traykov Link to this post

    Thank you so much for your help, Dilyan!
Back to Top