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

Loop appointments with multiple resources

1 Answer 109 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Peer
Top achievements
Rank 1
Peer asked on 21 Sep 2015, 02:01 PM

Hi.

 If i want to loop appointments, i do this:

 

       For Each a In uiRadSchedulerMain.Appointments

          Dim test = a.Start

          .....and so on.​

       Next a  

But what if i have 2, or more, resources to a appointment, how to loop these? I only get the first resourceId if eg. there are two or more resources to one appointment.​

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Sep 2015, 02:17 PM
Hello Peer,

Thank you for writing.
 
It is appropriate to use the Appointment.ResourceIds collection which gives you the EventIds of the associated resources.
public Form1()
{
    InitializeComponent();
    Color[] colors = new Color[]
    {
        Color.LightBlue, Color.LightGreen, Color.LightYellow,
        Color.Red, Color.Orange, Color.Pink, Color.Purple, Color.Peru, Color.PowderBlue
    };
 
    string[] names = new string[]
    {
        "Alan Smith", "Anne Dodsworth",
        "Boyan Mastoni", "Richard Duncan", "Maria Shnaider"
    };
 
    for (int i = 0; i < names.Length; i++)
    {
        Resource resource = new Resource();
        resource.Id = new EventId(i);
        resource.Name = names[i];
        resource.Color = colors[i];
         
        this.radScheduler1.Resources.Add(resource);
    }
    this.radScheduler1.GroupType = GroupType.Resource;
    this.radScheduler1.ActiveView.ResourcesPerView = this.radScheduler1.Resources.Count;
    Random rand = new Random();
    EventId id;
    for (int i = 0; i < 4; i++)
    {
        Appointment a = new Appointment(DateTime.Now, TimeSpan.FromHours(3), "Meeting" + i);
        id = this.radScheduler1.Resources[rand.Next(0, this.radScheduler1.Resources.Count)].Id;
        a.ResourceIds.Add(id);
        id = this.radScheduler1.Resources[rand.Next(0, this.radScheduler1.Resources.Count)].Id;
        if (!a.ResourceIds.Contains(id))
        {
            a.ResourceIds.Add(id);
        }
        this.radScheduler1.Appointments.Add(a);
    }
}
 
private void radButton1_Click(object sender, EventArgs e)
{
    foreach (Appointment a in this.radScheduler1.Appointments)
    {
        foreach (EventId id in a.ResourceIds)
        {
            Console.WriteLine(a.Summary + " " + id);
        }
    }
}

I hope this information helps. Should you have further questions I would be glad to help.
 
Regards,
Dess
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Scheduler and Reminder
Asked by
Peer
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or