Gantt task simultaneously as both parent and child

Hi!
Is there a way in Gantt C# to make a child as both parent and child?
If not, how can I show operations in the best way?

I need to get a view of operations in orders in order (for production purposes).

I am makings parents and childs by foreach loops in foreach loop.

private ObservableCollection<TaskDetails> GetDataSource()
        {
            int i = 0;
            ObservableCollection<TaskDetails> task = new ObservableCollection<TaskDetails>();
            ObservableCollection<TaskDetails> taskOperacja = new ObservableCollection<TaskDetails>();
            foreach (Model.Nadzlecenie nadzlec in ListaNadzlecen) //First orders getting with constructor
            {
                task.Add(
            new TaskDetails
            {
                TaskId = nadzlec.IdNzp,
                TaskName = nadzlec.NumerNzp,
                StartDate = nadzlec.StartZp,
                FinishDate = nadzlec.KoniecZP,
                Progress = 0
            });
                BindingList<Model.Zlecenie> ListaZlecen1 = PoleceniaSQL.PobierzZlecenia(nadzlec.IdNzp); //Second orders
                foreach (Model.Zlecenie zlec in ListaZlecen1)
                {
                    task[i].Child.Add(
                    new TaskDetails
                    {
                        TaskId = zlec.IdNzp,
                        TaskName = zlec.NumerZP + " " + zlec.KodTwr,
                        StartDate = zlec.StartZp,
                        FinishDate = zlec.KoniecZP,
                        Progress = 0
                    });


                    BindingList<Model.Operacja> ListaOperacji1 = PoleceniaSQL.PobierzOperacje(zlec.Idzp); //Operations
                    //TODO: Operations
                    //foreach (Model.Operacja ope in ListaOperacji1)
                    //{
                    // taskOperacja.Add(
                    //new TaskDetails
                    //{
                    // TaskId = zlec.IdNzp,
                    // TaskName = zlec.NumerZP + " " + zlec.KodTwr,
                    // StartDate = zlec.StartZp,
                    // FinishDate = zlec.KoniecZP,
                    // Progress = 0
                    //});


                    // taskOperacja[0].Child.Add(
                    //new TaskDetails
                    //{
                    // TaskId = ope.IdCzynnosci,
                    // TaskName = ope.NazwaOperacji,
                    // StartDate = ope.Start,
                    // FinishDate = ope.Koniec,
                    // Progress = 0
                    //});
                    //}
                }
                i++;
            }
            return task;
        }

Kind Regards,
Mateusz Kubis


3 Replies

VR Vignesh Ramesh Syncfusion Team September 2, 2021 04:30 PM UTC

Hi Mateusz Kubis, 

Greetings from Syncfusion 

We have analyzed your query and it can be achieved by setting multiple hierarchy data for GanttControl’s ItemsSource as like below code snippet. 

[C#]: 
List<TaskDetails> task = new List<TaskDetails>(); 
task.Add(new TaskDetails 
{ 
    TaskId = 1, 
    TaskName = "Order", 
    StartDate = new DateTime(2011, 7, 3), 
    Duration = new TimeSpan(2, 0, 0, 0), 
    FinishDate = new DateTime(2011, 7, 4), 
    Progress = 55d 
}); 
 
task[0].Child.Add(new TaskDetails 
{ 
    TaskId = 2, 
    TaskName = "Order1", 
    StartDate = new DateTime(2011, 7, 3), 
    Duration = new TimeSpan(2, 0, 0, 0), 
    FinishDate = new DateTime(2011, 7, 5), 
    Progress = 70d 
}); 
 
task[0].Child[0].Child.Add(new TaskDetails 
{ 
    TaskId = 3, 
    TaskName = "Operation1", 
    StartDate = new DateTime(2011, 7, 7), 
    Duration = new TimeSpan(2, 0, 0, 0), 
    FinishDate = new DateTime(2011, 7, 10), 
    Progress = 58d 
}); 
 
task[0].Child[0].Child.Add(new TaskDetails 
{ 
    TaskId = 4, 
    TaskName = "Operation2", 
    StartDate = new DateTime(2011, 7, 3), 
    Duration = new TimeSpan(2, 0, 0, 0), 
    FinishDate = new DateTime(2011, 7, 5), 
    Progress = 80d 
}); 

Also, we have prepared the sample for the same. Please get it from below link. 

Output: 
 

If your requirement is different from this, please provide additional information (like pictorial representation, etc) on your requirement. This would be helpful for us to give a better solution. 

Regards, 
Vignesh Ramesh.


MK Mateusz Kubis October 22, 2021 01:12 PM UTC

Thanks! It helped a lot!



ET Eswaran Thirugnanasambandam Syncfusion Team October 25, 2021 06:37 AM UTC

Hi Mateusz Kubis, 
 
Thanks for your update, 
 
Let us know, if you need further assistance. 
 
Regards, 
Eswaran 


Loader.
Up arrow icon