/// <summary> /// Removes the first occurrence of a specific object from the /// <see cref="T:System.Collections.Generic.ICollection`1" />. /// </summary> /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1" />.</param> /// <returns> /// true if <paramref name="item" /> was successfully removed from the /// <see cref="T:System.Collections.Generic.ICollection`1" />; otherwise, false. This method also returns false if /// <paramref name="item" /> is not found in the original <see cref="T:System.Collections.Generic.ICollection`1" />. /// </returns> public virtual bool Remove(T item) { var index = ItemsCore.IndexOf(item); if (index < 0) { return(false); } ItemsCore.RemoveAt(index); return(true); }
/// <summary> /// Replaces an item in the selector's collection. /// </summary> /// <param name="prevItem">The item to replace.</param> /// <param name="newItem">The item to replace <paramref name="prevItem" /> with.</param> /// <returns>true if the item could be replaced; otherwise, false.</returns> public virtual bool Replace(T prevItem, T newItem) { var index = ItemsCore.IndexOf(prevItem); if (index < 0) { return(false); } ItemsCore[index] = newItem; return(true); }
/// <summary> /// Replaces an item in the selector's collection and selects the new item. /// </summary> /// <param name="prevItem">The item to replace.</param> /// <param name="newItem">The item to replace <paramref name="prevItem" /> with.</param> /// <returns>true if the item could be replaced; otherwise, false.</returns> public virtual bool ReplaceAndSelect(T prevItem, T newItem) { var index = ItemsCore.IndexOf(prevItem); if (index < 0) { return(false); } if (index == SelectedIndex) { SelectedIndex = -1; } ItemsCore[index] = newItem; SelectedIndex = index; return(true); }
/// <summary> /// Determines the index of a specific item in the <see cref="T:System.Collections.Generic.IList`1" />. /// </summary> /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.IList`1" />.</param> /// <returns> /// The index of <paramref name="item" /> if found in the list; otherwise, -1. /// </returns> public int IndexOf(T item) { return(ItemsCore.IndexOf(item)); }