GanttView not only facilitates you to create project schedules, but also helps you in keeping your project data consistent. It does so by prohibiting invalid data entries or modifications to avoid conflicts. For instance, it prevents cyclic connection between tasks to avoid illogical task relationships. Here, a cyclic connection refers to a connection that occurs when the successor task and the predecessor task are the same for a given task.
The following GIF shows how GanttView prohibits the user to create a cyclic connection between tasks.
To avoid cyclic connection in GanttView, follow the given steps:
C# |
Copy Code
|
---|---|
public static class Extensions { public static IEnumerable<Task> FindCyclicTasks(this Task task) { return task.Predecessors.Select(x => x.PredecessorTask).Intersect(task.Successors); } } |
C# |
Copy Code
|
---|---|
gv.Tasks.ListChanged += OnListChanged; |
C# |
Copy Code
|
---|---|
private void OnListChanged(object? sender, System.ComponentModel.ListChangedEventArgs e) { foreach (Task task in gv.Tasks) { if (task.Initialized) { // find cyclic tasks var cyclicTasks = task.FindCyclicTasks(); if (cyclicTasks.Any()) { // clear cylcic tasks var predecessors = task.Predecessors.Join(cyclicTasks, predecessor => predecessor.PredecessorTaskID, successor => successor.ID, (predecessor, successor) => predecessor).ToList(); foreach (var predecessor in predecessors) task.Predecessors.Remove(predecessor); } } } } |