buy now
log in
MindFusion

Q: What is the best way to programatically select an item in the Calendar control?

I have the CurrentView set to Timetable, and I have a number of items added to the Schedule associated with this View. Essentially, I want to be able to select the item, so that it moves into view in the Calendar and changes to the selected style, as if the user clicked the item. There is no in-place Editing.

A: To select items programatically, add them to the Calendar.ItemSelection collection. To deselect items, remove them from the collection. The following code selects the item referenced by the variable 'item'.

	  calendar.ItemSelection.Add(item);
  

Q: Which property would enable me to get each of those selected days and show them, for example, in a message box for display?

A: You can access the selected time ranges through the Calendar.Selection.Ranges property. This property returns an ArrayList of even number DateTime objects, sorted in a chronological order. Each pair in the list represents a selected time range. For example, if you have selected a single time range 01/01 0:00 AM to 15/01 0:00 AM, then the array returned by this property will contain 2 DateTime object - (01/01 0:00 AM) and (15/01 0:00 AM) respectively.

Q: What is the meaning of the Multiple Selection?

A: Setting SelectionAllowMultiple to State.Disabled prevents users from selecting range of dates, i.e. they can only select a single date. Clicking and dragging with the mouse will not select several dates, but rather only the last pointed date before the mouse is released. For example, when this property is disabled, in a Single Month view the users would be able to select only a single day cell, while in Resource view, they would be able to select only a single moment in time (which usually results in the selection not being visible).

In general, Calendar.Selection corresponds to the date/time selection within the control, while Calendar.ItemSelection corresponds to the appointment selection.

Q: How to disable multiple item selection?

I am using the calendar with Resource view. I would like to allow only one appointment to be selected at a given time. I tried to set Calendar.SelectionAllowMultiple = Disabled but I can still select multiple items (by holding down the Ctrl button and clicking on the items). Any suggestions?

A: You can achieve it easily by handling the Calendar.ItemSelectionChanged event. The following code gives an idea on how to do it: Code:

private void calendar_ItemSelectionChanged(object sender, 
      ItemSelectionEventArgs e)
{
	if (e.IsSelected)
	{
		calendar.ItemSelection.Clear();
		calendar.ItemSelection.Add(e.Item);
	}
} 

Copyright © 2001-2017 MindFusion LLC. All rights reserved.
Terms of Use - Contact Us