/// <summary> /// Removes all items from the collection. /// </summary> /// <remarks> /// This implementation raises the CollectionChanged event. /// </remarks> protected override void ClearItems() { EnsureValidThread(); base.ClearItems(); _owner.UpdateMonths(); }
/// <summary> /// Adds all the dates in the specified range, which includes the first /// and last dates, to the collection. /// </summary> /// <param name="start">The first date to add to the collection.</param> /// <param name="end">The last date to add to the collection.</param> public void AddRange(DateTime start, DateTime end) { DateTime?rangeStart; // increment parameter specifies if the Days were selected in // Descending order or Ascending order based on this value, we add // the days in the range either in Ascending order or in Descending // order int increment = (DateTime.Compare(end, start) >= 0) ? 1 : -1; _addedItems.Clear(); rangeStart = start; _isRangeAdded = true; if (_owner.IsMouseSelection) { // In Mouse Selection we allow the user to be able to add // multiple ranges in one action in MultipleRange Mode. In // SingleRange Mode, we only add the first selected range. while (rangeStart.HasValue && DateTime.Compare(end, rangeStart.Value) != -increment) { if (CalendarEx.IsValidDateSelection(_owner, rangeStart)) { Add(rangeStart.Value); } else { if (_owner.SelectionMode == CalendarExSelectionMode.SingleRange) { _owner.HoverEnd = rangeStart.Value.AddDays(-increment); break; } } rangeStart = DateTimeHelper.AddDays(rangeStart.Value, increment); } } else { // If CalendarSelectionMode.SingleRange and a user // programmatically tries to add multiple ranges, we will throw // away the old range and replace it with the new one. In order // to provide the removed items without an additional event, we // are calling ClearInternal if (_owner.SelectionMode == CalendarExSelectionMode.SingleRange && Count > 0) { foreach (DateTime item in this) { _owner.RemovedItems.Add(item); } ClearInternal(); } while (rangeStart.HasValue && DateTime.Compare(end, rangeStart.Value) != -increment) { Add(rangeStart.Value); rangeStart = DateTimeHelper.AddDays(rangeStart.Value, increment); } } _owner.OnSelectedDatesCollectionChanged(new SelectionChangedEventArgs(_owner.RemovedItems, _addedItems)); _owner.RemovedItems.Clear(); _owner.UpdateMonths(); _isRangeAdded = false; }