Loop appointments with multiple resources

2 posts, 1 answers
  1. Peer
    Peer avatar
    2 posts
    Member since:
    Aug 2015

    Posted 21 Sep 2015 Link to this post

    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.​

  2. Answer
    Dess
    Admin
    Dess avatar
    1609 posts

    Posted 21 Sep 2015 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top