private void ListView_ItemsRemoving(object sender, ItemsRemovingEventArgs e)
 {
     foreach (var o in e.ObjectsToRemove)
     {
         SourceObjects.Remove(o);
     }
 }
        /// <summary>
        /// Remove all of the given objects from the control
        /// </summary>
        /// <param name="modelObjects">Collection of objects to be removed</param>
        /// <remarks>
        /// <para>Nulls and model objects that are not in the ListView are silently ignored.</para>
        /// <para>Due to problems in the underlying ListView, if you remove all the objects from
        /// the control using this method and the list scroll vertically when you do so,
        /// then when you subsequenially add more objects to the control,
        /// the vertical scroll bar will become confused and the control will draw one or more
        /// blank lines at the top of the list. </para>
        /// </remarks>
        public override void RemoveObjects(ICollection modelObjects)
        {
            if (this.DataSource == null)
            {
                return;
            }

            // Give the world a chance to cancel or change the removed objects
            ItemsRemovingEventArgs args = new ItemsRemovingEventArgs(modelObjects);

            this.OnItemsRemoving(args);
            if (args.Canceled)
            {
                return;
            }

            this.ClearCachedInfo();
            this.DataSource.RemoveObjects(args.ObjectsToRemove);
            this.UpdateVirtualListSize();
        }
Пример #3
0
		/// <summary>
		/// Remove all of the given objects from the control
		/// </summary>
		/// <param name="modelObjects">Collection of objects to be removed</param>
		/// <remarks>
		/// <para>Nulls and model objects that are not in the ListView are silently ignored.</para>
		/// <para>Due to problems in the underlying ListView, if you remove all the objects from
		/// the control using this method and the list scroll vertically when you do so,
		/// then when you subsequenially add more objects to the control,
		/// the vertical scroll bar will become confused and the control will draw one or more
		/// blank lines at the top of the list. </para>
		/// </remarks>
		public override void RemoveObjects(ICollection modelObjects) {
			if (this.DataSource == null)
				return;

			// Give the world a chance to cancel or change the removed objects
			ItemsRemovingEventArgs args = new ItemsRemovingEventArgs(modelObjects);
			this.OnItemsRemoving(args);
			if (args.Canceled)
				return;

			this.ClearCachedInfo();
			this.DataSource.RemoveObjects(args.ObjectsToRemove);
			this.UpdateVirtualListSize();
		}