Example #1
0
        private void RemoveGroup(DataGridCollectionViewGroup group)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group");
            }

            Debug.Assert(this == group.m_parent);

            // We do not remove group forced in SubGroupBy.GroupNames
            if (group.UnsortedIndex < this.SubGroupBy.GroupNames.Count)
            {
                return;
            }

            Debug.Assert(!this.IsBottomLevel);
            Debug.Assert((group.m_globalRawItemCount == 0) && (group.ProtectedItemCount == 0));

            this.ProtectedItemCount--;
            m_groupsDictionary.Remove(DataGridCollectionViewGroup.GetHashKeyFromName(group.Name));
            this.ProtectedItems.Remove(group);

            if ((this.ProtectedItemCount == 0) && (m_parent != null))
            {
                m_parent.RemoveGroup(this);
            }
        }
        internal bool Contains(object item)
        {
            var group = item as DataGridCollectionViewGroup;

            if (group != null)
            {
                //Must make sure the group the group is ref equals, because there can be groups with a null name at more than one level.
                DataGridCollectionViewGroup foundGroup;
                if (m_subGroups.TryGetValue(DataGridCollectionViewGroup.GetHashKeyFromName(group.Name), out foundGroup))
                {
                    return(foundGroup == group);
                }

                return(false);
            }

            DataGridCollectionView collectionView = this.GetCollectionView();

            if (collectionView != null)
            {
                RawItem rawItem = collectionView.GetFirstRawItemFromDataItem(item);
                if (rawItem != null)
                {
                    return(rawItem.ParentGroup == this);
                }
            }

            return(false);
        }
Example #3
0
        private void InsertGroup(int index, DataGridCollectionViewGroup group)
        {
            Debug.Assert(!this.IsBottomLevel);

            m_groupsDictionary.Add(DataGridCollectionViewGroup.GetHashKeyFromName(group.Name), group);
            this.ProtectedItemCount++;
            this.ProtectedItems.Insert(index, group);
        }
Example #4
0
        internal DataGridCollectionViewGroup GetGroup(
            RawItem rawItem,
            int level,
            CultureInfo culture,
            ObservableCollection <GroupDescription> groupByList,
            GroupSortComparer[] groupSortComparers)
        {
            // If sortComparers is null, we are in massive group creation, no order check.

            if (this.IsBottomLevel)
            {
                throw new InvalidOperationException("An attempt was made to get a group for which a GroupDescription has not been provided.");
            }

            object groupName = m_subGroupBy.GroupNameFromItem(rawItem.DataItem, level, culture);
            DataGridGroupDescription    dataGridGroupDescription = m_subGroupBy as DataGridGroupDescription;
            DataGridCollectionViewGroup group;

            if (dataGridGroupDescription != null)
            {
                group = m_groupsDictionary[DataGridCollectionViewGroup.GetHashKeyFromName(groupName)]
                        as DataGridCollectionViewGroup;
            }
            else
            {
                int itemCount = this.ItemCount;
                group = null;

                for (int i = 0; i < itemCount; i++)
                {
                    DataGridCollectionViewGroup tempGroup = this.ProtectedItems[i] as DataGridCollectionViewGroup;

                    if (m_subGroupBy.NamesMatch(tempGroup.Name, groupName))
                    {
                        group = tempGroup;
                        break;
                    }
                }
            }

            if (group == null)
            {
                group = this.CreateSubGroup(
                    groupName, level, groupByList, groupSortComparers);
            }

            return(group);
        }
        internal DataGridCollectionViewGroup GetGroup(
            RawItem rawItem,
            int level,
            CultureInfo culture,
            ObservableCollection <GroupDescription> groupByList,
            List <GroupSortComparer> groupSortComparers)
        {
            // If sortComparers is null, we are in massive group creation, no order check.

            if (this.IsBottomLevel)
            {
                throw new InvalidOperationException("An attempt was made to get a group for which a GroupDescription has not been provided.");
            }

            object groupName = m_subGroupBy.GroupNameFromItem(rawItem.DataItem, level, culture);
            DataGridCollectionViewGroup group;

            if ((m_subGroupBy is DataGridGroupDescription) || (m_subGroupBy is PropertyGroupDescription))
            {
                m_subGroups.TryGetValue(DataGridCollectionViewGroup.GetHashKeyFromName(groupName), out group);
            }
            else
            {
                //If dealing with an unknown GroupDescription type, use the standard method to retrieve a group, in case group retrival is handle differently.
                group = null;

                foreach (var tempGroup in m_subGroups.Values)
                {
                    if (m_subGroupBy.NamesMatch(tempGroup.Name, groupName))
                    {
                        group = tempGroup;
                        break;
                    }
                }
            }

            if (group == null)
            {
                group = this.CreateSubGroup(groupName, level, groupByList, groupSortComparers);
            }

            return(group);
        }