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

Custom GanttTask with custom children's class

3 Answers 85 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
Kenny
Top achievements
Rank 1
Kenny asked on 19 Jun 2013, 11:06 AM
Hello,
In my project I'm using a custom collection which derrives from ObservableCollection, ex. CustomGanttCollection : ObservableCollection<CustomGanttTask>
This gives me the possibility to add some extra methods...

The same way as I declared my CustomGanttCollection
, I declared my custom gantt task as: CustomGanttTask : GanttTask

Now I thought using my CustomCollection as the Collection where the ChildTask are stored in by overriding the Children property of GanttTask in my CustomGantTask like:

private <span style="font-size: 14px;">CustomGanttCollection _children</span><br>public <span style="font-size: 14px;">CustomGanttCollection Children<br></span>{<br><span class="Apple-tab-span" style="white-space:pre"> </span>get<br><span class="Apple-tab-span" style="white-space:pre"> </span>{<br><span class="Apple-tab-span" style="white-space:pre">       </span>return _children;<br><span class="Apple-tab-span" style="white-space:pre">   </span>}<br>}


Offcourse I do add some tasks in my ViewModel to the children...

Although this works (no compile errors, when I take a look at the Children property everything looks fine,...)  the GanttView Component won't show me the childtasks.

Is there a way that I can use my custom collection as the children's collection? The GanttView must be able to use the collection as it already uses one for the top-level tasks...

3 Answers, 1 is accepted

Sort by
0
Kenny
Top achievements
Rank 1
answered on 19 Jun 2013, 11:07 AM
Hello,
In my project I'm using a custom collection which derrives from ObservableCollection, ex. CustomGanttCollection : ObservableCollection<CustomGanttTask>
This gives me the possibility to add some extra methods...

The same way as I declared my CustomGanttCollection
, I declared my custom gantt task as: CustomGanttTask : GanttTask

Now I thought using my CustomCollection as the Collection where the ChildTask are stored in by overriding the Children property of GanttTask in my CustomGantTask like:

private CustomGanttCollection _children;
public CustomGanttCollection Children
{
get
{
return _children;
}
}



Offcourse I do add some tasks in my ViewModel to the children...

Although this works (no compile errors, when I take a look at the Children property everything looks fine,...)  the GanttView Component won't show me the childtasks.

Is there a way that I can use my custom collection as the children's collection? The GanttView must be able to use the collection as it already uses one for the top-level tasks...
0
Miroslav Nedyalkov
Telerik team
answered on 19 Jun 2013, 04:20 PM
Hello Kenny,

From your sample code I can see that you have a property called Children which actually hides the Children property of the GanttTask, but the GanttView doesn't know about it and because of that it ignores it.

There is no easy to implement alternative of your approach as the GanttTask class doesn't support its Children replaced to be changed - it creates its own in its constructor and it cannot be changed later.

I can suggest you two different approaches which have their positives and negatives depending on your needs:
1. If you need just to add functionality to your tasks collection (methods) and you don't need to add any data to it (properties and fields), I would suggest you to create some extension methods instead of inheriting the collection. This might also remove the need of inheriting the GanttTask class.
2. As the GanttView also doesn't know about the GanttTask class, but only about the interfaces - IGanttTask, IMilestone, ISummary, IEditableHierarchical, IDependant, implemented by the GanttTask class, you could create your own implementation, which doesn't inherit from the GanttTask class.

The second approach is more complicated, but allows you greater flexibility.

Regards,
Miroslav Nedyalkov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Kenny
Top achievements
Rank 1
answered on 21 Jun 2013, 03:16 PM
Hello Miroslav,

I solved it by doing a sync between my Children property and the base.Children property.

In the constructor of my custom ganttask;

_children = new MyCustomCollection(_project);
_children.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(_children_CollectionChanged);

And:

void _children_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
// Do a sync between _children (actually MyCustomCollection : ObservableCollection<CustomGanttTask>) and base.Children
}

This way I can use any collection I want, as long as I keep them synchronised...
Tags
GanttView
Asked by
Kenny
Top achievements
Rank 1
Answers by
Kenny
Top achievements
Rank 1
Miroslav Nedyalkov
Telerik team
Share this question
or