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

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

4 Answers 69 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
Bahram
Top achievements
Rank 1
Bahram asked on 20 Mar 2019, 05:20 AM

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

4 Answers, 1 is accepted

Sort by
0
Accepted
Dilyan Traykov
Telerik team
answered on 22 Mar 2019, 03:45 PM
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.
0
Bahram
Top achievements
Rank 1
answered on 23 Mar 2019, 09:15 PM

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)?

0
Accepted
Dilyan Traykov
Telerik team
answered on 25 Mar 2019, 03:25 PM
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.
0
Bahram
Top achievements
Rank 1
answered on 06 Apr 2019, 06:49 PM
Thank you so much for your help, Dilyan!
Tags
GanttView
Asked by
Bahram
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Bahram
Top achievements
Rank 1
Share this question
or