Is there an event in RadScheduler when a user selects a resource?

2 Answers 60 Views
Scheduler and Reminder
Troy
Top achievements
Rank 3
Bronze
Iron
Iron
Troy asked on 03 Jan 2022, 01:11 AM

I'd like to automatically update the description box content based on the resource the user has selected.  I haven't had any luck finding an event to detect when the resource is updated in an appointment.  Any suggestions?


Thanks!

2 Answers, 1 is accepted

Sort by
1
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Jan 2022, 07:40 AM
Hello, Troy,

Thank you for clarifying that you want to detect the resource selection changing in the EditAppointmentDialog. Indeed, in this case you will need to follow a different approach: 
            this.radScheduler1.AppointmentEditDialogShowing += radScheduler1_AppointmentEditDialogShowing;

        private void radScheduler1_AppointmentEditDialogShowing(object sender, AppointmentEditDialogShowingEventArgs e)
        {
            EditAppointmentDialog editDialog = e.AppointmentEditDialog as EditAppointmentDialog;
            if (editDialog != null)
            {
                editDialog.Shown += editDialog_Shown;
            }
        }

        private void editDialog_Shown(object sender, EventArgs e)
        {
            EditAppointmentDialog editDialog = sender as EditAppointmentDialog;
            RadCheckedDropDownList checkedCmbResource = editDialog.Controls["checkedCmbResource"] as RadCheckedDropDownList;
            checkedCmbResource.ItemCheckedChanged -= checkedCmbResource_ItemCheckedChanged;
            checkedCmbResource.ItemCheckedChanged += checkedCmbResource_ItemCheckedChanged;
        }

        private void checkedCmbResource_ItemCheckedChanged(object sender, RadCheckedListDataItemEventArgs e)
        {
            RadMessageBox.Show(e.Item.Text + " >> checked = " + e.Item.Checked);
        }

I believe that it would fit your scenario.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Troy
Top achievements
Rank 3
Bronze
Iron
Iron
commented on 03 Jan 2022, 05:45 PM

Thank you very much Dess, that's what I needed!
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Jan 2022, 07:17 AM
Hello, Troy,

I have prepared a sample code snippet demonstrating how to detect when a scheduler cell is clicked and detect what is the affected resource. Hence, it is easy to determine when the selected resource is changed considering the last clicked resource:
        public RadForm1()
        {
            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; 

            this.radScheduler1.CellSelectionChanging += radScheduler1_CellSelectionChanging;
        }

        Resource lastSelectedResource = null; 

        private void radScheduler1_CellSelectionChanging(object sender, SchedulerCellSelectingEventArgs e)
        {
            if (e.Cell != null)
            {
                Resource selectedResource = GetResourceByID(e.SelectionResourceId);
                if (selectedResource != null && selectedResource != lastSelectedResource)
                {
                    lastSelectedResource = selectedResource;
                    this.Text = lastSelectedResource.Name;
                }
            }
        }

        private Resource GetResourceByID(EventId eventId)
        {
            foreach (Resource r in this.radScheduler1.Resources)
            {
                if (r.Id.KeyValue == eventId.KeyValue)
                {
                    return r;
                }
            }
            return null;
        }

The attached gif file illustrates the achieved result.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Troy
Top achievements
Rank 3
Bronze
Iron
Iron
commented on 03 Jan 2022, 07:24 AM

Dess,

 

thank you for your very detailed reply.  However I'm looking for when a user changes the selected Resource on the EditAppointmentDialog form.  Unless I'm missing something in your reply?

Tags
Scheduler and Reminder
Asked by
Troy
Top achievements
Rank 3
Bronze
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or