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

VisibleRange - possible bug (or my mistake)

4 Answers 91 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
Paweł
Top achievements
Rank 1
Paweł asked on 18 Sep 2012, 11:48 AM
Hi,

I don't know whether is it my mistake or bug in the Gantt control.
Description:

I try to implement buttons that change time period displayed in Gantt. To do this, in my view I have:

<telerik:RadGanttView x:Name="gantMain" 
                              TasksSource="{Binding Activities}"
                              SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                              VisibleRange="{Binding GanttRange, Mode=OneWay}">

This is no surprise, as it's described in Gantt guide. Additionally, button is declared like this:

 <customTelerikControls:ToolBarButton x:Name="btnVisibilityCurrentMonth"
                                      cal:Message.Attach="Visibility_CurrentMonth"                                                
                                      Text="Current Month" />

Code in viewmodel:

private IDateRange _GanttRange; 
public IDateRange GanttRange
{
    get
    {
       return _GanttRange;
    }
    set
    {
        if (_GanttRange != value)
        {
           _GanttRange = value;
           NotifyOfPropertyChange(() => GanttRange);
        }
     }
}
public void Visibility_CurrentMonth()
        {
            DateTime now = DateTime.Now;
            DateTime start = new DateTime(now.Year, now.Month, 1);
            DateTime end = new DateTime(now.Year, now.Month, DateTime.DaysInMonth(now.Year, now.Month));
            GanttRange = new VisibleRange(start, end.AddDays(1)); //TODO: why do I need to add one day????????
        }
Question is: why do I need to add one day in visible range ctor to display full month? If I don't add this one day, September will be displayed from 1st to 29th. Best regards Paweł

4 Answers, 1 is accepted

Sort by
0
Miroslav Nedyalkov
Telerik team
answered on 20 Sep 2012, 12:13 PM
Hello Pawel,

The problem you are observing is caused, because the VisibleRange you are using is actually from the beginning of the 1st of September to the beginning of the 30th of September which doesn't include all the hour of 30th of September in this range, but just its beginning. That is why adding one more day makes 30th of September visible - because not only its start is in the visible range, but the whole day is there, too.

In short you just need to use the last hour of the date you want to use as a VisibleRange end to include the whole date in the rendered range.

Hope this helps.

Greetings,
Miroslav Nedyalkov
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Paweł
Top achievements
Rank 1
answered on 20 Sep 2012, 12:17 PM
Hi,

Is this behavior intended? Because I see it not intuitive.
Regards
Paweł
0
Accepted
Miroslav Nedyalkov
Telerik team
answered on 21 Sep 2012, 08:24 AM
Hello Pawel,

Yes, this behavior is intended, because the RadGanttView doesn't round the input VisibleRange to any value which allows you to work with arbitrary dates. Of course this brings this non-intuitive side effect you observed that if you write VisibleRange from 2012/09/01 to 2012/09/30 it will not actually include the 2012/09/30, but it will end right at its beginning, but if you think for it in another way like start from 2012/09/01 and continue 1 month (i.e. 30 days) it will actually give 2912/10/01. This code is not going to work as expected if the GanttView always includes the whole day of the range End.

My advise is to convert your code to the following:
DateTime now = DateTime.Now;
DateTime start = new DateTime(now.Year, now.Month, 1);
DateTime end = start.AddMonth(1);
GanttRange = new VisibleRange(start, end);

Hope this helps.

All the best,
Miroslav Nedyalkov
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Paweł
Top achievements
Rank 1
answered on 21 Sep 2012, 12:36 PM
Hi again, Miroslav  

Thank you for advice. Most important for me is that the behavior is intended and won't be changed in the future, so I won't be forced to change this code after switch to next version of controls :)
Best regards
Paweł
Tags
GanttView
Asked by
Paweł
Top achievements
Rank 1
Answers by
Miroslav Nedyalkov
Telerik team
Paweł
Top achievements
Rank 1
Share this question
or