Completed
Last Updated: 18 Apr 2019 13:50 by ADMIN
Release R2 2019
Jacint
Created on: 15 Apr 2019 07:33
Category: UI for WinForms
Type: Bug Report
1
RadScheduler: The OffsetView method with a 0 step always returns the current month view
Calling the OffsetView method with a 0 step should return the view currently displayed in the control. At the moment the view is adjusted according to DateTime.Now.
1 comment
ADMIN
Hristo
Posted on: 15 Apr 2019 07:40
Hi,

Workaround: don`t call the OffsetView method with a 0 step or use the custom scheduler below.
public class CustomRadScheduler : RadScheduler
{
    private FieldInfo schedulerFi;
    private FieldInfo activeViewsFi;
    private MethodInfo onPropertyChangedMi;
    private MethodInfo setActiveViewMi;
 
    protected override void CreateChildItems(RadElement parent)
    {
        base.CreateChildItems(parent);
 
        this.activeViewsFi = typeof(RadScheduler).GetField("activeViews", BindingFlags.Instance | BindingFlags.NonPublic);
        this.schedulerFi = typeof(SchedulerView).GetField("scheduler", BindingFlags.Instance | BindingFlags.NonPublic);
        this.onPropertyChangedMi = typeof(SchedulerView).GetMethod("OnPropertyChanged", BindingFlags.Instance | BindingFlags.NonPublic);
        this.setActiveViewMi = typeof(RadScheduler).GetMethod("SetActiveView", BindingFlags.Instance | BindingFlags.NonPublic);
    }
 
    public override string ThemeClassName
    {
        get
        {
            return typeof(RadScheduler).FullName;
        }
    }
 
    /// <summary>
    /// Gets or sets the type of the active view.
    /// </summary>
    /// <value>The type of the active view.</value>
    [DefaultValue(SchedulerViewType.Day)]
    [NotifyParentProperty(true)]
    public override SchedulerViewType ActiveViewType
    {
        get
        {
            return base.ActiveViewType;
        }
        set
        {
            if (this.ActiveViewType != value && value == SchedulerViewType.Month)
            {
                SchedulerView newView;
                Dictionary<SchedulerViewType, SchedulerView> activeViews = this.activeViewsFi.GetValue(this) as Dictionary<SchedulerViewType, SchedulerView>;
                if (activeViews.ContainsKey(value))
                {
                    newView = activeViews[value];
                }
                else
                {
                    SchedulerView view = new CustomSchedulerMonthView();
                    this.schedulerFi.SetValue(view, this);
                    this.onPropertyChangedMi.Invoke(view, new object[] { new string[] { "Scheduler" } });
                    newView = view;
                }
 
                if (this.ActiveView != newView && newView != null)
                {
                    this.setActiveViewMi.Invoke(this, new object[] { newView, true });
                }
            }
            else
            {
                base.ActiveViewType = value;
            }
        }
    }
}
 
public class CustomSchedulerMonthView : SchedulerMonthView
{
    public override SchedulerView OffsetView(int offset)
    {
        if (offset == 0)
        {
            return this;
        }
 
        return base.OffsetView(offset);
    }
}


Regards,
Hristo
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.