System.Windows.Forms.ListBox.SelectedIndexCollection.AddCore C# (CSharp) Method

AddCore() private method

private AddCore ( int index ) : bool
index int
return bool
			internal bool AddCore (int index)
			{
				if (selection.Contains (index))
					return false;

				if (index == -1) // Weird MS behaviour
					return false;
				if (index < -1 || index >= owner.Items.Count)
					throw new ArgumentOutOfRangeException ("index");
				if (owner.selection_mode == SelectionMode.None)
					throw new InvalidOperationException ("Cannot call this method when selection mode is SelectionMode.None");

				if (owner.selection_mode == SelectionMode.One && Count > 0) // Unselect previously selected item
					RemoveCore ((int)selection [0]);

				selection.Add (index);
				sorting_needed = true;
				owner.EnsureVisible (index);
				owner.FocusedItem = index;
				owner.InvalidateItem (index);
#if NET_2_0
				// UIA Framework event: Selected item added
				OnUIACollectionChangedEvent (new CollectionChangeEventArgs (CollectionChangeAction.Add, index));
#endif 

				return true;
			}