System.Windows.Forms.ListView.ListViewItemCollection.RemoveAt C# (CSharp) Method

RemoveAt() public method

public RemoveAt ( int index ) : void
index int
return void
			public virtual void RemoveAt (int index)
			{
				if (index < 0 || index >= Count)
					throw new ArgumentOutOfRangeException ("index");

				if (owner != null && owner.VirtualMode)
					throw new InvalidOperationException ();

				ListViewItem item = (ListViewItem) list [index];

				bool selection_changed = false;
				if (is_main_collection && owner != null) {

					int display_index = item.DisplayIndex;
					if (item.Focused && display_index + 1 == Count) // Last item
						owner.SetFocusedItem (display_index == 0 ? -1 : display_index - 1);

					selection_changed = owner.SelectedIndices.Contains (index);
					owner.item_control.CancelEdit (item);
				}

				list.RemoveAt (index);

				if (is_main_collection) {
					item.Owner = null;
					if (item.Group != null)
						item.Group.Items.Remove (item);
				} else
					item.SetGroup (null);

				CollectionChanged (false);
				if (selection_changed && owner != null)
					owner.OnSelectedIndexChanged (EventArgs.Empty);


				//UIA Framework event: Item Removed 
				OnUIACollectionChangedEvent (new CollectionChangeEventArgs (CollectionChangeAction.Remove, item));
			}