Horizontal scrolling on GanttChart

3 posts, 1 answers
  1. Natalia
    Natalia  avatar
    4 posts
    Member since:
    Mar 2014

    Posted 11 Jun 2014 Link to this post

    Hi,

    I want to assign some calculated values to scrollbar's  offset of GanttChart view but cann't do that. There are couple of gantt tasks that have default Start and End values:
    ganttTask.Start = DateTime.MinValue;
    ganttTask.End = DateTime.MinValue;

    In this cases if user selects this ganttTask on the ColumnsPanel, the horizontal scrollbar of EventsPanel moves to the start of  GanttChart's VisibleRange. I suppose it tries to show me that task via scrolling to its Start date. But this is not what I need. I  want the horizontal scrollbar to stay at the same position as it was before selection. To achieve this I've binded a SelectedItem property to a view model's property and when it is changed I assign another horizontal offset value :
    public ScheduleItem SelectedItem
            {
                get
                {
                    return _selectedItem;
                }
                set
                {
                    _selectedItem = value;
                  // SomeType : IGanttTask and for all items of SomeType the next comes true: 
                  //Start = DateTime.MinValue;
                  // End = DateTime.MinValue;
                    if (_selectedItem is SomeType)
                    {
                        EventsPanel.HorizontalOffset = HorisontalPannelOffset;
                    }
                    RaisePropertyChanged(() => SelectedItem);
                }
            }
    Here, the EventsPanel is a view model's property that referens to the GanttView's EventsPanel property. And this approach doesn't work for me. The scrollbar moves to the start of VisibleRange.  I wonder is there a way to set the horizontal offset for the selected gantt task?

    Thanks any help.

    Kind regards,
    Natalia Novosad
  2. Answer
    Polya
    Admin
    Polya avatar
    200 posts

    Posted 12 Jun 2014 Link to this post

    Hi Natalia,

    Currently we do not allow modifications in the scrolling settings.
    However, we can scroll into view of the previously selected item when the currently selected item has Start and End dates equal to DateTime.MinValue.
    First we have to hook to RadGanttView.SelectionChanged:
    public MainWindow()
    {
        InitializeComponent();
        this.gantt.SelectionChanged += gantt_SelectionChanged;
    }
    and then in the gantt_SelectionChanged method we should scroll to the previously selected GanttTask if the new one has DateTime.Min dates:
    private void gantt_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var gantt = sender as RadGanttView;
        var previousItems = e.RemovedItems;      
        var newItems = e.AddedItems;
     
        if (newItems.Count == 1)
        {
            var newGanttItem = newItems[0] as GanttTask;
     
            //this is how we check if it is a GanttTask has Start and End dates = DateTime.MinValue
            if (newGanttItem.Start == DateTime.MinValue && newGanttItem.End == DateTime.MinValue)
            {
                var settings = new ScrollSettings() { HorizontalScrollPosition = HorizontalScrollPosition.Left, VerticalScrollPosition = VerticalScrollPosition.Anywhere };
                if (previousItems.Count > 0)
                    gantt.ScrollingService.ScrollIntoView(previousItems[0], settings);
            }
        }
    }

    Please take a look and let me know if it works for you.

    Regards,
    Polya
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Natalia
    Natalia  avatar
    4 posts
    Member since:
    Mar 2014

    Posted 13 Jun 2014 in reply to Polya Link to this post

    Hi Polya,

    Thank you for reply, it helped me to solve the issue.

    Kind regards,
    Natalia Novosad
Back to Top