/// <summary> /// Finds the index of the specified item /// </summary> /// <param name="item">Item we are looking for</param> /// <param name="seed">Seed of the item we are looking for</param> /// <param name="comparer">Comparer used to find the item</param> /// <param name="low">Low range of item index</param> /// <param name="high">High range of item index</param> /// <returns>Index of the specified item</returns> protected virtual int FindIndex(object item, object seed, IComparer comparer, int low, int high) { int index; if (comparer != null) { ListComparer listComparer = comparer as ListComparer; if (listComparer != null) { // reset the IListComparer before each search. This cannot be done // any less frequently (e.g. in Root.AddToSubgroups), due to the // possibility that the item may appear in more than one subgroup. listComparer.Reset(); } CollectionViewGroupComparer groupComparer = comparer as CollectionViewGroupComparer; if (groupComparer != null) { // reset the CollectionViewGroupComparer before each search. This cannot be done // any less frequently (e.g. in Root.AddToSubgroups), due to the // possibility that the item may appear in more than one subgroup. groupComparer.Reset(); } for (index = low; index < high; ++index) { CollectionViewGroupInternal subgroup = this.ProtectedItems[index] as CollectionViewGroupInternal; object seed1 = (subgroup != null) ? subgroup.SeedItem : this.ProtectedItems[index]; if (seed1 == DependencyProperty.UnsetValue) { continue; } if (comparer.Compare(seed, seed1) < 0) { break; } } } else { index = high; } return(index); }