/// <summary> /// Raises the <see cref="E:ItemsChanging"/> event. /// </summary> /// <param name="e">The <see cref="ItemsChangingEventArgs"/> instance containing the event data.</param> protected virtual void OnItemsChanging(ItemsChangingEventArgs e) { if (this.ItemsChanging != null) { this.ItemsChanging(this, e); } }
/// <summary> /// Set the collection of objects that this control will show. /// </summary> /// <param name="collection"></param> /// <remark>This method can safely be called from background threads.</remark> public override void SetObjects(IEnumerable collection) { if (InvokeRequired) { Invoke((MethodInvoker) delegate { SetObjects(collection); }); return; } if (DataSource == null) { return; } BeginUpdate(); try { // Give the world a chance to cancel or change the assigned collection var args = new ItemsChangingEventArgs(null, collection); OnItemsChanging(args); if (args.Canceled) { return; } DataSource.SetObjects(args.NewObjects); UpdateVirtualListSize(); Sort(); } finally { EndUpdate(); } }