Schedule - A list of Appointments of two different types

1 Answer 60 Views
ScheduleView
Ohad
Top achievements
Rank 3
Bronze
Iron
Iron
Ohad asked on 19 Jan 2023, 02:17 PM | edited on 19 Jan 2023, 02:28 PM

Suppose I have an Abstract Class C that inherits from Appointment and Classes A and B that inherit from C.

Class C is only inherited from Appointment but has nothing in it.

public abstract class C : Appointment { }

And classes A and B have overrides for Copy and CopyFrom

The AppointmentSource list is actually a C list.

I am currently having a problem with Drop when I drag an object of type A or B on the board and reach the

if (state.Appointment is A)
{
    base.Drop(state);
}

I get an Exception.

From what I see it probably comes from CreateNew, CopyFrom, etc.

If C is not abstract, it creates an object of type C, That is C which is neither A nor B

I verify it in AppointmentCreated

I would appreciate help on how to do this correctly

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 24 Jan 2023, 09:03 AM

Hello Ohad,

This happens because the RadScheduleView uses a ListCollectionView internally. The adding of a new item is based on the CanAddNew value of the collection view. The CanAddNew property checks few factors of the collection type, which in your case is AppointmentC. One of these factors is if the class can initiated using an empty constructor. However, because your class is abstract, the collection view cannot create a new instance of it, thus it the CanAddNew is false and the newly created item is null, which throws the reported error. 

To achieve your requirement, you will need to change the item type of the collection assigned to the AppointmentsSource property of RadScheduleView. For example, you can use the Appointment type.

scheduleView.AppointmentsSource = new ObservableCollection<Appointment>();
source.Add(new AppointmentA());
source.Add(new AppointmentB());

Or alternatively, you can remove the "abstract" class modifier from the AppointmentC class.

public class C : Appointment { }

I hope this information helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ScheduleView
Asked by
Ohad
Top achievements
Rank 3
Bronze
Iron
Iron
Answers by
Martin Ivanov
Telerik team
Share this question
or