Auto-disabling Past Time Slots

7 posts, 0 answers
  1. Jeremy Murtishaw
    Jeremy Murtishaw avatar
    86 posts
    Member since:
    Apr 2009

    Posted 25 Apr 2010 Link to this post

    Hello,

    Is there a way to automatically disable any past days and time slots in the RadScheduler? I have a function that does the calculation, but it seems unreliable. Sometimes if the user performs certain actions, the past time slots will become active again. I'll post my code below.

    if (this.radScheduler.SchedulerElement.ViewElement is SchedulerDayViewElement) 
                { 
                    SchedulerDayViewElement dayView = this.radScheduler.SchedulerElement.ViewElement as SchedulerDayViewElement; 
     
                    if (dayView != null
                    { 
                        foreach (RadElement element in dayView.DataAreaElement.Table.Children) 
                        { 
     
                            SchedulerCellElement cell = element as SchedulerCellElement; 
                            if (cell != null
                            { 
                                if (cell.Date <= DateTime.Now) 
                                { 
                                    cell.Enabled = false
                                    cell.CanFocus = false
                                } 
                                else 
                                { 
                                    cell.Enabled = true
                                    cell.CanFocus = true
                                } 
                            } 
                        } 
                    } 
                } 
                else if (this.radScheduler.SchedulerElement.ViewElement is SchedulerMonthViewElement) 
                { 
                    SchedulerMonthViewElement monthView = this.radScheduler.SchedulerElement.ViewElement as SchedulerMonthViewElement; 
                    foreach (RadElement element in monthView.MonthViewAreaElement.Children) 
                    { 
                        if (element is MonthCellElement) 
                        { 
     
                            MonthCellElement e = element as MonthCellElement; 
                            if (e.Date < DateTime.Now.Date) 
                            { 
                                element.Enabled = false
                            } 
                        } 
                    } 
                } 


    Thanks!
    Jeremy
  2. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 29 Apr 2010 Link to this post

    Hi Jeremy Murtishaw,

    Thank you for contacting us.

    Disabling cells is not supported in RadScheduler for WinForms, because we need to recreate the view when a specific property is changed. For example when you change the range factor of the ruler, the view needs to be recreated, because the timeslot count would be different.

    We would like to get more details on your scenario, if possible, in order to see whether this is a good feature to have. What is the purpose of disabling the old scheduler cells? Do you need to cancel the selection of these cells or create a new appointment for a past time slot?

    Looking forward to your reply.
     
    Sincerely yours,
    Boyko Markov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jeremy Murtishaw
    Jeremy Murtishaw avatar
    86 posts
    Member since:
    Apr 2009

    Posted 29 Apr 2010 Link to this post

    Hi Boyko,

    The purpose of this functionality is to paint the past time-slots gray and make them un-selectable for the creation of appointments. I think this makes the tool more intuitive for the user since they can see the current time where the grayed-out cells meet the colored ones.

    Colin
  5. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 30 Apr 2010 Link to this post

    Hello Jeremy Murtishaw,

    I agree that this would be a great feature to be built in RadScheduler, something like locked cells or locked  dates. Unfortunately, we cannot implement this feature as a workaround. As I see from your previous post, you get the cells collection depending on the scheduler's current view. You can also do this by using the GetCells method of the SchedulerUIHelper:

    List<SchedulerCellElement> cells = SchedulerUIHelper.GetCells(this.radScheduler);

    If you want to cancel the creation of an Appointment for a previous date, you can do the following:

    1. Subscribe to the AppointmentEditDialogShowing event of RadScheduler.
    2. In the event handler, set the AppointmentEditDialog property to null in case you need to cancel showing the default dialog that allows you to create a new appointment or edit an existing one.

    void radScheduler_AppointmentEditDialogShowing(object sender, AppointmentEditDialogShowingEventArgs e)
     {
         List<SchedulerCellElement> cells = SchedulerUIHelper.GetSelectedCells(this.radScheduler);
         if (cells.Count > 0)
         {
             if (cells[0].Date < DateTime.Now)
             {
                 e.AppointmentEditDialog = null;
                 return;
             }
             else
             {
                 e.AppointmentEditDialog = new EditAppointmentDialog(e.Appointment, this.radScheduler);
                 return;
             }
         }
         else
         {
             e.AppointmentEditDialog = new EditAppointmentDialog(e.Appointment, this.radScheduler);
         }
     }

    I hope this helps.



    Regards,
    Boyko Markov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Erdem
    Erdem avatar
    14 posts
    Member since:
    Apr 2012

    Posted 24 Apr 2012 Link to this post

    How can we do this ? where we can add this code ? I want to auto-disable past day please help :)
  7. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 27 Apr 2012 Link to this post

    Hi Erdem,

    Thank you for writing.

    Before answering your question, I would like to mention that I noticed that you have only downloaded the Telerik ASP.NET AJAX suite. Please note that this forum concerns the WinForms version of RadScheduler. If your question is about the ASP.NET AJAX version of RadScheduler, please ask it in the corresponding forums.

    If your question concerns the WinForms version of RadScheduler, then you can use the following code to achieve the scenario discussed in this thread:
    public Form1()
    {
        InitializeComponent();
        this.radScheduler1.CellFormatting += new EventHandler<Telerik.WinControls.UI.SchedulerCellEventArgs>(radScheduler1_CellFormatting);
        this.radScheduler1.AppointmentDropping += new EventHandler<AppointmentMovingEventArgs>(radScheduler1_AppointmentDropping);
        this.radScheduler1.AppointmentMoving += new EventHandler<AppointmentMovingEventArgs>(radScheduler1_AppointmentMoving);
        this.radScheduler1.AppointmentResizing += new EventHandler<AppointmentResizingEventArgs>(radScheduler1_AppointmentResizing);
        this.radScheduler1.Appointments.CollectionChanging += new Telerik.WinControls.Data.NotifyCollectionChangingEventHandler(Appointments_CollectionChanging);
        this.radScheduler1.ActiveView = new SchedulerDayView(DateTime.Today.AddDays(-1), DateTime.Today.AddDays(1));
    }
     
    void radScheduler1_AppointmentResizing(object sender, AppointmentResizingEventArgs e)
    {
        if (e.NewStartDate < DateTime.Today)
        {
            e.Cancel = true;
        }
    }
     
    void Appointments_CollectionChanging(object sender, Telerik.WinControls.Data.NotifyCollectionChangingEventArgs e)
    {
        if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Add &&
            ((Appointment)e.NewItems[0]).Start < DateTime.Today)
        {
            e.Cancel = true;
        }
    }
     
    void radScheduler1_AppointmentMoving(object sender, AppointmentMovingEventArgs e)
    {
        if (e.NewDate < DateTime.Today)
        {
            e.Cancel = true;
        }
    }
     
    void radScheduler1_AppointmentDropping(object sender, AppointmentMovingEventArgs e)
    {
        if (e.NewDate < DateTime.Today)
        {
            e.Cancel = true;
        }
    }
     
    void radScheduler1_CellFormatting(object sender, Telerik.WinControls.UI.SchedulerCellEventArgs e)
    {
        if (e.CellElement.Date < DateTime.Today)
        {
            e.CellElement.Enabled = false;
        }
    }

    The above code is the full code behind of a form with a RadScheduler instance added in the designer, so you should be able to easily incorporate it in your project.

    I hope this will help you. Feel free to ask if you have any additional questions.

    All the best,
    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  8. Erdem
    Erdem avatar
    14 posts
    Member since:
    Apr 2012

    Posted 28 Apr 2012 Link to this post

    Thank you very much for your reply and thank you very much telerik team ...
Back to Top
UI for WinForms is Visual Studio 2017 Ready