How to create new appointment programmatically?

13 posts, 0 answers
  1. Kian
    Kian avatar
    15 posts
    Member since:
    Sep 2010

    Posted 30 Sep 2010 Link to this post

    Dear Admin,

    I have a RadScheduler with ActiveViewType = Day and RadScheduler1.GroupType = GroupType.Resource which my resources are my Employee.
    I wrote this code to create an appointment, but it does not work and my RadScheduler does not show the appointment:

     

     

     

    Private Sub NewAppointment(ByVal StartDateTime As Date, ByVal EndDateTime As Date, ByVal EmployeeID As Integer) 
        Dim duration As Long = DateAndTime.DateDiff(DateInterval.Hour, StartDateTime, EndDateTime) 
        Dim apt As New Appointment() 
        apt.Start = StartDateTime
        apt.End = StartDateTime.AddHours(duration)
        apt.Summary = "Summary Test"
        apt.ResourceId = 
        New EventId(EmployeeID) 

        'RadScheduler1.Appointments.Add(apt) 

        RadScheduler1.ActiveView.Appointments.Add(apt)
    End Sub

     

    What did I wrong?

    I am looking forward to hearin from you as soon as possible.
    Thank you in advanced.
    Kian

     

     

     

     

     

     

  2. Dobry Zranchev
    Admin
    Dobry Zranchev avatar
    348 posts

    Posted 05 Oct 2010 Link to this post

    Hello Kian,

    Thank you for writing.

    Generally, it is not a good practise to add an appointment directly to the view. You should add your appointments to the Appointments collection of RadScheduler
    Dim StartDateTime As DateTime = Me.radScheduler1.ActiveView.StartDate
    Dim apt As New Appointment()
    apt.Start = StartDateTime
    apt.[End] = StartDateTime.Add(New TimeSpan(1, 0, 0))
    apt.Summary = "Summary Test"
    apt.ResourceId = New EventId(2)
     
    radScheduler1.Appointments.Add(apt)

    You will not see the added appointment only if the resources collection of the scheduler does not contain the resource id.

    If you have other questions, feel free to write back.

    Kind regards,
    Dobry Zranchev
    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. Ramiro
    Ramiro avatar
    3 posts
    Member since:
    Jun 2009

    Posted 13 Oct 2010 Link to this post

    Hi, Could you tell me the past code but to work with C#.
    Thank you
  5. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 13 Oct 2010 Link to this post

    Hello Ramiro,

    If you want to convert some code from vb to c# or from c# to vb, you can always use the Code Converter provided by telerik.

    Following is the code that Dobry posted, converted to C#:
    DateTime StartDateTime = this.radScheduler1.ActiveView.StartDate;
    Appointment apt = new Appointment();
    apt.Start = StartDateTime;
    apt.End = StartDateTime.Add(new TimeSpan(1, 0, 0));
    apt.Summary = "Summary Test";
    apt.ResourceId = new EventId(2);
     
    radScheduler1.Appointments.Add(apt);

    Best Regards,
    Emanuel Varga
  6. bradhh
    bradhh avatar
    25 posts
    Member since:
    Feb 2007

    Posted 10 Mar 2011 Link to this post

    I copied the code from your example (VB), and I'm getting this error:

       'Telerik.Web.UI.AppointmentCollection.Friend Sub Add(apt As Telerik.Web.UI.Appointment)'
       is not accessible in this context because it is 'Friend'.

    Has this functionality changed since your response? It appears that this example worked previously. If not, what am I doing wrong? I'm trying to use this code inside the TimeSlotContextMenuItemClicking event handler to automatically create an appointment without the user having to use the dialog box to name it.

    Thanks!

    Brad




  7. bradhh
    bradhh avatar
    25 posts
    Member since:
    Feb 2007

    Posted 10 Mar 2011 Link to this post

    OK, I think I've figured out the solution to this particular issue. Instead of:

    RadScheduler1.Appointments.Add(apt)

    I should use this:

    RadScheduler1.InsertAppointment(apt)

    This seems to work in this case.

    Thanks!
    Brad
  8. Arul
    Arul avatar
    2 posts
    Member since:
    Sep 2010

    Posted 30 Oct 2012 Link to this post

    The following piece of code creates 2 appointments but at the same date and time . It should be two different items

      Telerik.Web.UI.Appointment meetingAppointment = new Telerik.Web.UI.Appointment();
                meetingAppointment.Subject = "Test";
                meetingAppointment.Start = DateTime.Now;
                meetingAppointment.End = DateTime.Now;
               
                RadScheduler1.InsertAppointment(meetingAppointment);
                 
               
                TimeSpan ts = new TimeSpan(0, 12, 0, 0);
         meetingAppointment.Subject = "Test2";
                meetingAppointment.Start = DateTime.Now + ts;
                meetingAppointment.End = DateTime.Now + ts;
                
                RadScheduler1.InsertAppointment(meetingAppointment);   
  9. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 02 Nov 2012 Link to this post

    Hello Brad,

    Thank you for writing.

    This forum concerns RadScheduler for WinForms and your questions seems to concern the RadScheduler for ASP.NET AJAX. Please address your question to the appropriate forums: http://www.telerik.com/community/forums/aspnet-ajax/scheduler.aspx.

    Kind regards,
    Stefan
    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
  10. Taher
    Taher avatar
    1 posts
    Member since:
    Nov 2013

    Posted 21 Nov 2013 Link to this post

    Hi.
    Please help me. I want to add appointment with code. Please write to me how can i do this. (with header and all thing to do this).thanks


  11. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 21 Nov 2013 Link to this post

    Hi Taher,

    You simply have to create an instance of the Appointment class, populate the desired properties of the object and add it to the Appointments collection of RadScheduler. Here is a sample explaining this: http://www.telerik.com/help/winforms/scheduler-appointments-and-dialogs-working-with-appointments.html.

    I hope this helps.

    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  12. Jeffrey
    Jeffrey avatar
    14 posts
    Member since:
    Mar 2014

    Posted 21 Mar 2014 in reply to Dobry Zranchev Link to this post

    HI this works for one appointment. But when trying to add to appointments one after another (if used in a loop) only the last appointment is added. How do I add multiple appointments with different start, end, summer, and description dates. Below is code that would only display second appointment and not first:

    Dim StartDateTime As DateTime = Me.RadScheduler1.ActiveView.StartDate
            Dim apt As New Appointment()
            apt.Start = StartDateTime
            apt.[End] = StartDateTime.Add(New TimeSpan(23, 59, 59))
            apt.Summary = "Client #0001"
            apt.Description = "Counselor Jeff"
            apt.ResourceId = New EventId(2)


            RadScheduler1.Appointments.Add(apt)


            apt.Start = StartDateTime
            apt.[End] = StartDateTime.Add(New TimeSpan(23, 59, 59))
            apt.Summary = "Client #0002"
            apt.Description = "Counselor Shanti"
            apt.ResourceId = New EventId(2)


            RadScheduler1.Appointments.Add(apt)
  13. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 26 Mar 2014 Link to this post

    Hello,

    The issue here comes from the fact that you are only changing the properties of the very same object you have created. If you want to use the same variable, you need to reinstantiate it with "New":
    Dim StartDateTime As DateTime = Me.RadScheduler1.ActiveView.StartDate
            Dim apt As New Appointment()
            apt.Start = StartDateTime
            apt.[End] = StartDateTime.Add(New TimeSpan(23, 59, 59))
            apt.Summary = "Client #0001"
            apt.Description = "Counselor Jeff"
            apt.ResourceId = New EventId(2)
     
     
            RadScheduler1.Appointments.Add(apt)
     
           Dim apt As New Appointment()
     
            apt.Start = StartDateTime
            apt.[End] = StartDateTime.Add(New TimeSpan(23, 59, 59))
            apt.Summary = "Client #0002"
            apt.Description = "Counselor Shanti"
            apt.ResourceId = New EventId(2)
     
     
            RadScheduler1.Appointments.Add(apt)

    I hope this helps.

    Regards,
    Stefan
    Telerik
     

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

     
  14. Jeffrey
    Jeffrey avatar
    14 posts
    Member since:
    Mar 2014

    Posted 27 Mar 2014 in reply to Stefan Link to this post

    Thanks worked great.
Back to Top
UI for WinForms is Visual Studio 2017 Ready