SchedualView with Drag-And-Drop, Created Appointment is always the parent type.

1 Answer 49 Views
DragAndDrop ListBox ScheduleView
Efi
Top achievements
Rank 1
Efi asked on 23 Jan 2023, 04:44 PM | edited on 23 Jan 2023, 04:45 PM

I have one parent type “Aa” inherit from “Telerik.Windows.Controls.ScheduleView.Appointment”, with two inherited types “Bb” and “Cc”. while each one has different properties implementation.

 

I have a RadScheduleView which it’s AppointmentsSource bounded to my ViewModel collection of parent type “Aa” (ObservableCollection<Aa>)

 

I also have two baskets, first one is a list of “Bb” items while the second one is a list of “Cc” items.

 

I can drag any item from each basket (“Aa” or “Bb”) and drop them on the ScheduleView so a new Appointment is created.

 

My problem is that the newly created appointment is always created from parent type “Aa” no matter which basket I selected to drag.

 

I want it to work according to the origin dragged item type so the new appointment will match the type “Bb” or “Cc”.

 

 

I Prepared a Sample code you can see here:

 

https://gist.github.com/EfiNadell/bcc10a8f93b210b7eaf626e67cf459a2

1 Answer, 1 is accepted

Sort by
1
Accepted
Dilyan Traykov
Telerik team
answered on 25 Jan 2023, 11:29 AM

Hello Efi,

Thank you for the provided sample code.

The RadScheduleView control internally works with an IEditableCollectionView which is created based on the passed AppointmentsSource.

Here's the CreateNew method of the RadScheduleView control for your reference:

		public IAppointment CreateNew(IAppointment appointment)
		{
			this.EnsureNotEditing();

			var newAppointment = this.DataConnection.AddNew();

			if (appointment != null)
			{
				newAppointment.CopyFrom(appointment);
			}

			if (newAppointment != null && this.OnAppointmentCreating(newAppointment))
			{
				this.IsAdding = true;
				this.EditedAppointment = newAppointment;
				return newAppointment;
			}
			this.DataConnection.CancelNew();
			return null;
		}

In the case of an ObservableCollection<Aa>, a ListCollectionView is created and its AddNew method returns instances of the passed generic type - Aa, in this case. This instance is actually returned as the newAppointment.

If you provide a custom IEditableCollectionView as the AppointmentsSource, the RadScheduleView will work directly with the methods of this custom view. In its AddNew method, you can explicitly return an item of the desired derived class, but you would need to somehow determine this in the Drop method override of the CustomScheduleViewDragDropBehavior class.

With this said, the RadScheduleView is not designed to work with heterogenic data and I would not advise using an AppointmentsSource with items of different types as it may lead to other undesired behavior.

What I would suggest in this case would be to have one common class for the appointments with all the possible properties and populate them accordingly based on the dragged item in the ConvertDraggedData of the CustomScheduleViewDragDropBehavior.

I hope you find this information helpful and that such an approach would work for you.

Regards,
Dilyan Traykov
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/.

Efi
Top achievements
Rank 1
commented on 29 Jan 2023, 08:52 AM

Thanks, I implemented your second approach and it's working fine.
Tags
DragAndDrop ListBox ScheduleView
Asked by
Efi
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or