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

Scroll to task when click on empty space

1 Answer 13 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 02 Feb 2015, 09:27 AM
I have GanttView. When I click on empty space of timeline I need scroll to task on this row. How I can do this?

1 Answer, 1 is accepted

Sort by
0
Polya
Telerik team
answered on 05 Feb 2015, 08:54 AM
Hi Alexander,

In order to achieve that we need to:

1) Add a MouseLeftButtonDown event handler to the BorderContainer (that is used as a placeholder for the row). Note that if you have SpecialSlotContainers you need to add the same handler to them as well because they are drawn on top of the BorderContainers.
public MainWindow()
{
    InitializeComponent();
    EventManager.RegisterClassHandler(typeof(BorderContainer), UIElement.MouseDownEvent, new MouseButtonEventHandler(OnMouseDown), true);
}
 
private void OnMouseDown(object sender, MouseButtonEventArgs e)
{
    var borderContainer = sender as BorderContainer;
    var info = borderContainer.DataItem as BorderInfo;
    var flattenedSource = this.FlattenSource().ToList();
    this.gantt.SelectedItem = flattenedSource[info.CellCoordinates.Start];
}

2) Implement the method FlattenSource that flattens the TasksSource of the RadGanttView in an IEnumerable<IGanttTask> and takes into account whether the GanttTasks are expanded or collapsed to extract the correct GanttTask corresponding to the BorderInfo.CellCoordinates.Start.
private IEnumerable<IGanttTask> FlattenSource(RadGanttView parentGantt)
{
    List<IGanttTask> result = new List<IGanttTask>();
    foreach (var task in parentGantt.TasksSource)
    {
        result.AddRange(this.FlattenSource(task as IGanttTask, parentGantt));
    }
 
    return result;
}
 
private IEnumerable<IGanttTask> FlattenSource(IGanttTask parent, RadGanttView parentGantt)
{
    yield return parent;
    foreach (var item in parent.Children)
    {
        var hierarchicalParent = parentGantt.ExpandCollapseService.HierarchicalCollectionAdapter.GetItemWrapperByItemKey(parent);
 
        var child = parentGantt.ExpandCollapseService.HierarchicalCollectionAdapter.GetItemWrapperByItemKey(item);
 
        if (hierarchicalParent.IsExpanded && (child.Children.Count == 0 || child.IsExpanded))
        {
            yield return item as IGanttTask;
        }
    }
}

Please note that the FlattenSource method will work correctly only for two levels of hierarchy, so you will need to improve it to support three or four levels by calling the same method recursively.

3) Finally set the RadGanttView.SelectedItem to the task from 2).

Hopefully this helps.

Regards,
Polya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GanttView
Asked by
Alexander
Top achievements
Rank 1
Answers by
Polya
Telerik team
Share this question
or