Example #1
0
        internal SelectionRangeWithItems(SelectionRange range, SharedList items)
        {
            if ((items.Count != range.Length) && (!range.IsEmpty))
            {
                throw new ArgumentException("selectionRange and items must have the same length.");
            }

            m_items = new OptimizedItemsList(items);
            m_range = range;
        }
Example #2
0
        public static void UpdateSelectionRangeWithItemsFromAdd(
            DataGridContext dataGridContext,
            SelectionRangeWithItems newRangeWithItems,
            ref SelectionRangeWithItems lastRangeWithItems)
        {
            // Only work for adding at the end of an existing range.

            object[] newRangeItems = newRangeWithItems.Items;

            if ((dataGridContext == null) ||
                ((dataGridContext.ItemsSourceCollection == null) && (newRangeItems == null)) ||
                (dataGridContext.ItemsSourceCollection is DataGridVirtualizingCollectionViewBase))
            {
                lastRangeWithItems = new SelectionRangeWithItems(new SelectionRange(lastRangeWithItems.Range.StartIndex, newRangeWithItems.Range.EndIndex), null);
                return;
            }

            SharedList newItemsList;

            if (newRangeWithItems == lastRangeWithItems)
            {
                if (newRangeItems != null)
                {
                    return;
                }

                newItemsList = new SharedList(lastRangeWithItems.Length);
            }
            else
            {
                int minNewCapacity = lastRangeWithItems.Length + newRangeWithItems.Length;

                // Optimization, re-use the ItemsList if available.
                if (lastRangeWithItems.SharedList != null)
                {
                    newItemsList = lastRangeWithItems.SharedList.Value;
                    newItemsList.EnsureCapacity(minNewCapacity);
                }
                else
                {
                    newItemsList = new SharedList(minNewCapacity);
                    newItemsList.AddRange(lastRangeWithItems.Items);
                }
            }

            var rangeToUpdateStartIndex = lastRangeWithItems.Range.StartIndex;
            var newRangeEndIndex        = newRangeWithItems.Range.EndIndex;

            // If new range have no items set, found the items and set it.
            if (newRangeItems == null)
            {
                var items = dataGridContext.Items;
                var newRangeStartIndex = newRangeWithItems.Range.StartIndex;

                if (newRangeEndIndex > newRangeStartIndex)
                {
                    for (int i = newRangeStartIndex; i <= newRangeEndIndex; i++)
                    {
                        newItemsList.Add(items.GetItemAt(i));
                    }
                }
                else
                {
                    for (int i = newRangeStartIndex; i >= newRangeEndIndex; i--)
                    {
                        newItemsList.Add(items.GetItemAt(i));
                    }
                }
            }
            else
            {
                newItemsList.AddRange(newRangeItems);
            }

            lastRangeWithItems = new SelectionRangeWithItems(new SelectionRange(rangeToUpdateStartIndex, newRangeEndIndex), newItemsList);
        }
Example #3
0
 public OptimizedItemsList(SharedList list)
 {
     m_itemsArray = null;
     m_itemsList  = list;
 }