Hi,
How can I manipulate which item (appointment) is selected in the XamOutlookCalendarView? I found that the SelectedActivities property contains the selected items' data but modifying this collection (add or remove elements) does not do any modification on which item is displayed as selected.I have to implement a search functionality which selects the first matching appointment and moves into view, but I did find how can I do that.
Thanks,Istvan
The SelectedActivities of the xamOutlookCalendarView is synchronized with the SelectedActivities of the ScheduleControlBase within for the current view (i.e. the DayView, MonthView or ScheduleView). I verified that clearing the collection or removing an item does affect the display. Adding an item to the selection is a bit more complicated because you have to get the Activity from the XamScheduleDataManager which depending on the DataConnector you are using (and its underlying storage) could be synchronous or asynchronous. Here's a simplified example. Note there is currently no public method for bringing an activity into view so you may want to submit a suggestion for adding that.
private void OnSearchClick(object sender, RoutedEventArgs e) { string text = this.searchText.Text; var data = (ScheduleData)this.DataContext; var dataManager = this.view.DataManager; var tzProvider = dataManager.DataConnector.TimeZoneInfoProviderResolved; if (string.IsNullOrEmpty(text)) return; // this is just a simple search to find the first. you'd probably want to // make you're own routine that continues/starts from the selected activity // and then wraps around as needed or possibly that just searches within a // given range foreach (var dataItem in data.Appointments) { string subject = dataItem.Subject; if (subject != null && subject.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) >= 0) { Resource resource = dataManager.ResourceItems.GetResourceFromId(dataItem.OwningResourceId); ResourceCalendar calendar = resource.Calendars.FirstOrDefault((c) => c.Id == dataItem.OwningCalendarId); Debug.Assert(calendar != null); if (calendar != null) { ActivityQuery query = new ActivityQuery(ActivityTypes.Appointment, new DateRange(dataItem.Start, dataItem.End), calendar); var result = dataManager.GetActivities(query); if (result.IsComplete) { var activity = result.Activities.FirstOrDefault((a) => a.DataItem == dataItem); if (activity != null) { this.view.SelectedActivities.Clear(); this.view.SelectedActivities.Add(activity); // currently there is no public method for bring an activity into view // but editing an activity will bring it into view. we can just // temporarily prevent editing if (dataManager.Settings == null) dataManager.Settings = new ScheduleSettings(); if (dataManager.Settings.AppointmentSettings == null) dataManager.Settings.AppointmentSettings = new AppointmentSettings(); var apptSettings = dataManager.Settings.AppointmentSettings; var cmd = new ScheduleControlBaseCommand(ScheduleControlCommand.EditSelectedActivity); var oldValue = apptSettings.AllowEdit; apptSettings.AllowEdit = false; cmd.Execute(this.view); apptSettings.AllowEdit = oldValue; } } else { // otherwise you have to hold the result, listen to the property change // for when the IsComplete is true and then access the activies and // manipulate the selected activities Debug.Assert(false, "Need to handle this"); } break; } } } }
if (string.IsNullOrEmpty(text)) return;
// this is just a simple search to find the first. you'd probably want to // make you're own routine that continues/starts from the selected activity // and then wraps around as needed or possibly that just searches within a // given range foreach (var dataItem in data.Appointments) { string subject = dataItem.Subject;
if (subject != null && subject.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) >= 0) { Resource resource = dataManager.ResourceItems.GetResourceFromId(dataItem.OwningResourceId); ResourceCalendar calendar = resource.Calendars.FirstOrDefault((c) => c.Id == dataItem.OwningCalendarId);
Debug.Assert(calendar != null);
if (calendar != null) { ActivityQuery query = new ActivityQuery(ActivityTypes.Appointment, new DateRange(dataItem.Start, dataItem.End), calendar); var result = dataManager.GetActivities(query);
if (result.IsComplete) { var activity = result.Activities.FirstOrDefault((a) => a.DataItem == dataItem);
if (activity != null) { this.view.SelectedActivities.Clear(); this.view.SelectedActivities.Add(activity);
// currently there is no public method for bring an activity into view // but editing an activity will bring it into view. we can just // temporarily prevent editing if (dataManager.Settings == null) dataManager.Settings = new ScheduleSettings();
if (dataManager.Settings.AppointmentSettings == null) dataManager.Settings.AppointmentSettings = new AppointmentSettings();
var apptSettings = dataManager.Settings.AppointmentSettings;
var cmd = new ScheduleControlBaseCommand(ScheduleControlCommand.EditSelectedActivity); var oldValue = apptSettings.AllowEdit; apptSettings.AllowEdit = false; cmd.Execute(this.view); apptSettings.AllowEdit = oldValue; } } else { // otherwise you have to hold the result, listen to the property change // for when the IsComplete is true and then access the activies and // manipulate the selected activities Debug.Assert(false, "Need to handle this"); } break; } } } }
Thanks to your answer - the selection and unselection of activities works fine.But unfortunatelly the way you wrote in the code to bring the activity into view didn't work - and I find a strange thing: when I select an activity which is currently out of the displayed range (in MonthView mode) and then I delete the selection the calendar scrolls to the day of previosly selected activity and selects that day (all selection and clear is done by code).
Istvan
Hello Istvan,
Here is the support ticket number: CAS-71263-8MN6D9 we have created on your behalf. I am going to link it to development issue: 85890 so that you get automatically updated when a Feature Release containing the fix is available for download. You can get the new version from our website’s “My IG”, “My Keys & Downloads” tags: https://ko.infragistics.com/Membership/Default.aspx?panel=Downloads#Downloads
You can also monitor the support ticket’s progress through the “My Support Activity” tag: https://ko.infragistics.com/Membership/MySupport.aspx
Thanks.
Before reading your post I tried to bring activity into view which date is out of the CurrentViewDateRange by setting the SelectedTimeRange to the range of the activity but didn't worked (I think because of missing to call VerifyState and UpdateLayout methods) ... So I tried with executing VisibleDatesPagePrevious and VisiblePageNext commands to change the CurrentViewDateRange and it's worked - so I'll use this embedded into your previously posted example.
istvanmolnar said:But unfortunatelly the way you wrote in the code to bring the activity into view didn't work
istvanmolnar said:and I find a strange thing: when I select an activity which is currently out of the displayed range (in MonthView mode) and then I delete the selection the calendar scrolls to the day of previosly selected activity and selects that day (all selection and clear is done by code).