Scroll to task when click on empty space

2 posts, 0 answers
  1. Alexander
    Alexander avatar
    6 posts
    Member since:
    Apr 2012

    Posted 02 Feb 2015 Link to this post

    I have GanttView. When I click on empty space of timeline I need scroll to task on this row. How I can do this?
  2. Polya
    Admin
    Polya avatar
    199 posts

    Posted 05 Feb 2015 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top