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

How Can I Assign a Resource to an Appointment Programmatically

3 Answers 288 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Anthony asked on 22 Aug 2013, 06:22 PM
Hi there,

I'm trying to assign resources to appointments in the code behind. When I assign them, the appointment displays the correct resource when I edit the appointment, however the appointment itself is displayed in the blank resource column.

Here is the XAML:
<telerik:RadScheduleView x:Name="ScheduleView" SnapAppointments="True">
    <telerik:RadScheduleView.ResourceTypesSource>
        <telerik:ResourceTypeCollection>
            <telerik:ResourceType DisplayName="Room" Name="Room">
                <telerik:Resource DisplayName="Room 1" ResourceName="Room 1" ResourceType="Room"/>
                <telerik:Resource DisplayName="Room 2" ResourceName="Room 2" ResourceType="Room"/>
            </telerik:ResourceType>
        </telerik:ResourceTypeCollection>               
    </telerik:RadScheduleView.ResourceTypesSource>
    <telerik:RadScheduleView.GroupDescriptionsSource>
        <telerik:GroupDescriptionCollection>
            <telerik:ResourceGroupDescription ResourceType="Room" ShowNullGroup="True"/>
        </telerik:GroupDescriptionCollection>
    </telerik:RadScheduleView.GroupDescriptionsSource>
    <telerik:RadScheduleView.ViewDefinitions>
        <telerik:DayViewDefinition DayStartTime="7:00" DayEndTime="19:00" MajorTickLength="1h" MinorTickLength="10min"/>
        <telerik:WeekViewDefinition DayStartTime="7:00" DayEndTime="19:00"/>
    </telerik:RadScheduleView.ViewDefinitions>
</telerik:RadScheduleView>

And here is the code behind:
private ObservableCollection<Appointment> appointments;
void ExamRoomScheduler_Loaded(object sender, RoutedEventArgs e)
{           
    appointments = new ObservableCollection<Appointment>();
    ScheduleView.AppointmentsSource = appointments;
 
    ExamRoomAppointment temp;
 
    temp = new ExamRoomAppointment("Test", DateTime.Now, DateTime.Now.AddMinutes(20), "Room 1");
    appointments.Add(temp);           
    temp.Resources.Add(new Resource() { ResourceType = "Room", ResourceName = "Room 1", DisplayName = "Room 1" });
}

ExamRoomAppointment inherits from Appointment.

I must be doing something wrong here but I can't seem to figure it out!

Thanks,
Anthony

3 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 26 Aug 2013, 09:53 AM
Hi Anthony,

If you need to add resources at run-time I would suggest that you check the following help article from our documentation:
http://www.telerik.com/help/wpf/radscheduleview-howto-update-resources.html#Adding_Resources

I'm also attaching here a sample project which demonstrates how to completely set up the resources in the code behind, please check the attachment.

Hope this helps. If you have any other questions let us know.

Regards,
Kalin
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Anthony
Top achievements
Rank 1
answered on 26 Aug 2013, 01:42 PM
Thanks Kalin,

Unfortunately that's not what I'm looking for. Adding the resources at run time isn't a problem. The issue is that I need to add the resources to the appointments so that they are grouped properly. When I assign the resources to the appointment the appointment editor shows the resource but the appointment is displayed in the blank group.

Anthony
0
Kalin
Telerik team
answered on 27 Aug 2013, 01:21 PM
Hi Anthony,

In order to have the appointment assigned to a particular resource you should add the same instance of the resource which is added to the ScheduleView resources. Please checked attached the same sample project which is modified to show the exact approach.

Hope this will work for you.

Regards,
Kalin
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
ScheduleView
Asked by
Anthony
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Anthony
Top achievements
Rank 1
Share this question
or