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

How to create new appointment programmatically?

12 Answers 528 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Kian
Top achievements
Rank 1
Kian asked on 30 Sep 2010, 10:14 AM
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

 

 

 

 

 

 

12 Answers, 1 is accepted

Sort by
0
Dobry Zranchev
Telerik team
answered on 05 Oct 2010, 04:19 PM
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
0
Ramiro
Top achievements
Rank 1
answered on 13 Oct 2010, 05:43 PM
Hi, Could you tell me the past code but to work with C#.
Thank you
0
Emanuel Varga
Top achievements
Rank 1
answered on 13 Oct 2010, 09:06 PM
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
0
bradhh
Top achievements
Rank 2
answered on 10 Mar 2011, 11:26 PM
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




0
bradhh
Top achievements
Rank 2
answered on 11 Mar 2011, 12:03 AM
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
0
Arul
Top achievements
Rank 1
answered on 30 Oct 2012, 10:21 PM
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);   
0
Stefan
Telerik team
answered on 02 Nov 2012, 10:07 AM
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
0
Taher
Top achievements
Rank 1
answered on 21 Nov 2013, 11:43 AM
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


0
Stefan
Telerik team
answered on 21 Nov 2013, 02:45 PM
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 >>
0
Jeffrey
Top achievements
Rank 1
answered on 21 Mar 2014, 02:02 PM
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)
0
Stefan
Telerik team
answered on 26 Mar 2014, 05:52 AM
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.

 
0
Jeffrey
Top achievements
Rank 1
answered on 27 Mar 2014, 02:18 PM
Thanks worked great.
Tags
Scheduler and Reminder
Asked by
Kian
Top achievements
Rank 1
Answers by
Dobry Zranchev
Telerik team
Ramiro
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
bradhh
Top achievements
Rank 2
Arul
Top achievements
Rank 1
Stefan
Telerik team
Taher
Top achievements
Rank 1
Jeffrey
Top achievements
Rank 1
Share this question
or