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

Horizontal scrolling on GanttChart

2 Answers 122 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
Natalia
Top achievements
Rank 1
Natalia asked on 11 Jun 2014, 11:28 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Polya
Telerik team
answered on 12 Jun 2014, 11:00 AM
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.
 
0
Natalia
Top achievements
Rank 1
answered on 13 Jun 2014, 12:57 PM
Hi Polya,

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

Kind regards,
Natalia Novosad
Tags
GanttView
Asked by
Natalia
Top achievements
Rank 1
Answers by
Polya
Telerik team
Natalia
Top achievements
Rank 1
Share this question
or