internal void SortItems(
            SortDescriptionInfo[] sortDescriptionInfos,
            List <GroupSortComparer> groupSortComparers,
            int level,
            List <RawItem> globalRawItems,
            DataGridCollectionViewGroup newSortedGroup)
        {
            int itemCount = this.ProtectedItemCount;

            if (itemCount == 0)
            {
                return;
            }

            if (this.IsBottomLevel)
            {
                int[] indexes;
                indexes = new int[itemCount + 1];
                for (int i = 0; i < itemCount; i++)
                {
                    indexes[i] = m_sortedRawItems[i].Index;
                }

                // "Weak heap sort" sort array[0..NUM_ELEMENTS-1] to array[1..NUM_ELEMENTS]
                DataGridCollectionViewSort collectionViewSort = new DataGridCollectionViewSort(indexes, sortDescriptionInfos);

                collectionViewSort.Sort(itemCount);
                int index = 0;

                for (int i = 1; i <= itemCount; i++)
                {
                    newSortedGroup.InsertRawItem(index, globalRawItems[indexes[i]]);
                    index++;
                }
            }
            else
            {
                int[] indexes;
                indexes = new int[itemCount + 1];
                for (int i = 0; i < itemCount; i++)
                {
                    indexes[i] = i;
                }

                DataGridCollectionViewGroup[] subGroupsArray = new DataGridCollectionViewGroup[itemCount];
                m_subGroups.Values.CopyTo(subGroupsArray, 0);

                // "Weak heap sort" sort array[0..NUM_ELEMENTS-1] to array[1..NUM_ELEMENTS]
                DataGridCollectionViewGroupSort collectionViewSort = new DataGridCollectionViewGroupSort(indexes, groupSortComparers[level], subGroupsArray);

                collectionViewSort.Sort(itemCount);
                int index = 0;
                level++;

                for (int i = 1; i <= itemCount; i++)
                {
                    DataGridCollectionViewGroup oldGroup = subGroupsArray[indexes[i]];
                    DataGridCollectionViewGroup newGroup = new DataGridCollectionViewGroup(oldGroup, newSortedGroup);

                    // Sort sub items
                    oldGroup.SortItems(sortDescriptionInfos, groupSortComparers, level, globalRawItems, newGroup);

                    newSortedGroup.InsertGroup(index, newGroup);
                    index++;
                }
            }
        }