VisibleRange - possible bug (or my mistake)

5 posts, 1 answers
  1. Paweł
    Paweł avatar
    11 posts
    Member since:
    Jun 2012

    Posted 18 Sep 2012 Link to this post

    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ł
  2. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 20 Sep 2012 Link to this post

    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.

  3. DevCraft banner
  4. Paweł
    Paweł avatar
    11 posts
    Member since:
    Jun 2012

    Posted 20 Sep 2012 Link to this post

    Hi,

    Is this behavior intended? Because I see it not intuitive.
    Regards
    Paweł
  5. Answer
    Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 21 Sep 2012 Link to this post

    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.

  6. Paweł
    Paweł avatar
    11 posts
    Member since:
    Jun 2012

    Posted 21 Sep 2012 Link to this post

    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ł
Back to Top
DevCraft banner