private void AddToSubgroup(object item, LiveShapingItem lsi, CollectionViewGroupInternal group, int level, object name, bool loading)
        {
            int    index        = !loading || !this.IsDataInGroupOrder ? 0 : group.LastIndex;
            object groupNameKey = this.GetGroupNameKey(name, group);
            CollectionViewGroupInternal subgroupFromMap;

            if ((subgroupFromMap = group.GetSubgroupFromMap(groupNameKey)) != null && group.GroupBy.NamesMatch(subgroupFromMap.Name, name))
            {
                group.LastIndex = group.Items[index] == subgroupFromMap ? index : 0;
                this.AddToSubgroups(item, lsi, subgroupFromMap, level + 1, loading);
            }
            else
            {
                for (int count = group.Items.Count; index < count; ++index)
                {
                    CollectionViewGroupInternal viewGroupInternal = group.Items[index] as CollectionViewGroupInternal;
                    if (viewGroupInternal != null && group.GroupBy.NamesMatch(viewGroupInternal.Name, name))
                    {
                        group.LastIndex = index;
                        group.AddSubgroupToMap(groupNameKey, viewGroupInternal);
                        this.AddToSubgroups(item, lsi, viewGroupInternal, level + 1, loading);
                        return;
                    }
                }
                CollectionViewGroupInternal viewGroupInternal1 = new CollectionViewGroupInternal(name, group);
                this.InitializeGroup(viewGroupInternal1, group.GroupBy, level + 1);
                if (loading)
                {
                    group.Add((object)viewGroupInternal1);
                    group.LastIndex = index;
                }
                else
                {
                    group.Insert((object)viewGroupInternal1, item, this.ActiveComparer);
                }
                group.AddSubgroupToMap(groupNameKey, viewGroupInternal1);
                this.AddToSubgroups(item, lsi, viewGroupInternal1, level + 1, loading);
            }
        }
        private void MoveWithinSubgroup(object item, CollectionViewGroupInternal group, int level, object name, IList list, int oldIndex, int newIndex)
        {
            object groupNameKey = this.GetGroupNameKey(name, group);
            CollectionViewGroupInternal subgroupFromMap;

            if ((subgroupFromMap = group.GetSubgroupFromMap(groupNameKey)) != null && group.GroupBy.NamesMatch(subgroupFromMap.Name, name))
            {
                this.MoveWithinSubgroups(item, subgroupFromMap, level + 1, list, oldIndex, newIndex);
            }
            else
            {
                int index = 0;
                for (int count = group.Items.Count; index < count; ++index)
                {
                    CollectionViewGroupInternal viewGroupInternal = group.Items[index] as CollectionViewGroupInternal;
                    if (viewGroupInternal != null && group.GroupBy.NamesMatch(viewGroupInternal.Name, name))
                    {
                        group.AddSubgroupToMap(groupNameKey, viewGroupInternal);
                        this.MoveWithinSubgroups(item, viewGroupInternal, level + 1, list, oldIndex, newIndex);
                        break;
                    }
                }
            }
        }