Is there any way I can select (clicking on) relationships in a RadGanttView so I can remove the relation between two tasks? (whether it's with right click -> delete or with a RadRibbonButton)
To achieve the required result, the Dependencies collection of the GanttTask instance, which has a dependency on another GanttTask instance, would have to be modified.
The following code snippet shows a sample implementation of the abovementioned logic, that executes when the PreviewMouseRightButtonDown event of that RadGanttView control is fired:
privatevoidganttView2_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.OriginalSource is Path)
{
var path = e.OriginalSource as Path;
var parentRelationContainer = path.ParentOfType<RelationContainer>();
if (parentRelationContainer != null)
{
MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show(
"Are you sure you want to delete this relation?",
"Delete Confirmation",
System.Windows.MessageBoxButton.YesNo);
if (messageBoxResult == MessageBoxResult.Yes)
{
var dataItem = (RelationInfo)parentRelationContainer.DataItem;
var taskFrom = dataItem.TaskFrom as GanttTask;
var taskTo = dataItem.TaskTo as GanttTask;
var dependency = taskTo.Dependencies.FirstOrDefault(x => x.FromTask == taskFrom) as Dependency;
if (dependency != null)
{
taskTo.RemoveDependency(dependency);
}
}
}
}
}
With this approach, by right-clicking on the Path element in the UI (the connection between two tasks), through the DataItem property of the RelationContainer class, the from and totasks are retrieved. Then, the from task is removed from the Dependencies collection of the to task.
Applying the abovementioned approach produces the following result:
I have attached a sample project for you to test.
Regards,
Stenly
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/.