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

Create Dynamic Appointment with spesific Source-Type

2 Answers 55 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Abdulaziz
Top achievements
Rank 1
Abdulaziz asked on 23 Jun 2014, 11:46 AM
I want To Create dynamic Appointment list and  dynamic Source Type in C# for my ScheduleView ,,
However: I already add dynamic Appointment and Resource with Resource Type ,,

But when i try to Assign resource-type to the Appointment I cant get it.

   public ObservableCollection<Appointment> Appointments { get; set; }
    public ObservableCollection<ResourceType> ResourceTypes { get; set; }



    private void MakeResources()
        {
            ResourceTypes = new ObservableCollection<ResourceType>();
            ResourceType rt = new ResourceType("Location");
            rt.Resources.Add(new Resource("Hall A", "Location"));
            rt.Resources.Add(new Resource("Hall B", "Location"));
            rt.Resources.Add(new Resource("Hall C", "Location"));
            ResourceTypes.Add(rt);

        TestScheduleView.ResourceTypesSource=ResourceTypes 
         }


   private void MakeAppointments()
        {
            Appointments = new ObservableCollection<Appointment>();
            for ( int i = 0; i < 10; i++)
            {
                Appointments.Add(new Appointment()
                {
                    Subject = "Appointment " + i.ToString(),
                    Start = DateTime.Now.AddHours(i),
                    End = DateTime.Now.AddHours(i).AddMinutes(30)

                });
            }
      AppointmentsSource.Source=Appointments 
        }




The Appointement List is Appear in ShedulView but How I can add them under The 
resource Type which I create?

I try to use

2 Answers, 1 is accepted

Sort by
0
Accepted
Lance | Manager Technical Support
Telerik team
answered on 23 Jun 2014, 03:27 PM
Hello Abdulaziz,

You can add a Resource to the appointment before adding it to the Appointments collection. Using your code, here is how to add a resource to a new appointment...

for (int i = 0; i < 10; i++)
            {
                //new-up an Appointment object
                var app = new Appointment()
                {
                    Subject = "Appointment " + i.ToString(),
                    Start = DateTime.Now.AddHours(i),
                    End = DateTime.Now.AddHours(i).AddMinutes(30),
 
                };
 
                //add the Resource to the appointment
                app.Resources.Add(new Resource("Hall A", "Location"));
 
                //add the appointment to the ScheduleView
                this.Appointments.Add(app);
            }


Note: you don't have to add the ResourceType when initially adding them, so you can shorten your approach to this:

var rt = new ResourceType("Location");
rt.Resources.Add(new Resource("Hall A"));
rt.Resources.Add(new Resource("Hall B"));
rt.Resources.Add(new Resource("Hall C"));
this.ResourceTypes.Add(rt);


I have built a sample application based on your code, find it attached. Go to MainViewModel.cs to see the implementation. I create sample appointments and add them to each Resource (Hall A, Hall B and Hall C). 

Thank you for contacting Support and thank you for choosing Telerik.

Regards,
Lance
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Abdulaziz
Top achievements
Rank 1
answered on 24 Jun 2014, 05:54 AM
Thanks Lance for your quick answer , and It's more Clear in your Example.

Tags
ScheduleView
Asked by
Abdulaziz
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Abdulaziz
Top achievements
Rank 1
Share this question
or