public int IndexOf(object item) { int indexOffset = 0; int count = m_list.Count; for (int i = 0; i < count; i++) { SelectionRangeWithItems rangeWithItems = m_list[i]; object[] items = rangeWithItems.Items; if (items != null) { int index = Array.IndexOf <object>(items, item); if (index != -1) { return(indexOffset + index); } } indexOffset += rangeWithItems.Length; } return(-1); }
public object this[int index] { get { if ((index < 0) || (index >= m_list.ItemsCount)) { throw new ArgumentOutOfRangeException("index", "The index must be equal or greater than zero and less than Count."); } int oldIndexOffset = 0; int indexOffset = 0; int count = m_list.Count; for (int i = 0; i < count; i++) { SelectionRangeWithItems rangeWithItems = m_list[i]; indexOffset += rangeWithItems.Length; if (index < indexOffset) { return(rangeWithItems.GetItem(m_list.DataGridContext, index - oldIndexOffset)); } oldIndexOffset = indexOffset; } throw new ArgumentOutOfRangeException("index", "The index must be less than Count."); } set { throw new NotSupportedException(); } }
public bool IsItemsEqual(SelectionRange rangeIntersection, SelectionRangeWithItems rangeWithItemsToCompare) { OptimizedItemsList itemsToCompare = rangeWithItemsToCompare.m_items; if ((m_items == null) || (itemsToCompare == null)) { return(true); } SelectionRange rangeToCompare = rangeWithItemsToCompare.Range; int startIndex = System.Math.Min(rangeIntersection.StartIndex, rangeIntersection.EndIndex); int itemIndex1 = System.Math.Abs(startIndex - m_range.StartIndex); int itemIndex2 = System.Math.Abs(startIndex - rangeToCompare.StartIndex); bool inversedRange1 = m_range.StartIndex > m_range.EndIndex; bool inversedRange2 = rangeToCompare.StartIndex > rangeToCompare.EndIndex; int count = rangeIntersection.Length; for (int i = 0; i < count; i++) { if (!object.Equals(m_items[itemIndex1], itemsToCompare[itemIndex2])) { return(false); } itemIndex1 = inversedRange1 ? itemIndex1 - 1 : itemIndex1 + 1; itemIndex2 = inversedRange2 ? itemIndex2 - 1 : itemIndex2 + 1; } return(true); }
public SelectionCellRangeWithItems(SelectionRange itemRange, object[] items, SelectionRange columnRange) { if ((items != null) && (items.Length != itemRange.Length)) { throw new ArgumentException("itemRange and items must have the same length."); } m_itemRangeWithItems = new SelectionRangeWithItems(itemRange, items); m_columnRange = columnRange; }
public void CopyTo(object[] array, int arrayIndex) { DataGridContext dataGridContext = m_list.DataGridContext; int count = m_list.Count; for (int i = 0; i < count; i++) { SelectionRangeWithItems rangeWithItems = m_list[i]; int rangeLength = rangeWithItems.Length; for (int j = 0; j < rangeLength; j++) { array[arrayIndex] = rangeWithItems.GetItem(dataGridContext, j); arrayIndex++; } } }
void ICollection.CopyTo(Array array, int arrayIndex) { DataGridContext dataGridContext = m_list.DataGridContext; int count = m_list.Count; for (int i = 0; i < count; i++) { SelectionRangeWithItems rangeWithItems = m_list[i]; int rangeLength = rangeWithItems.Length; for (int j = 0; j < rangeLength; j++) { array.SetValue(rangeWithItems.GetItem(dataGridContext, j), arrayIndex); arrayIndex++; } } }
public void RemoveAt(int index) { if ((index < 0) || (index >= m_list.ItemsCount)) { throw new ArgumentOutOfRangeException("index", index, "index must be greater than or equal to zero and less than Count."); } int oldIndexOffset = 0; int indexOffset = 0; int count = m_list.Count; SelectionRangeWithItems rangeWithItemsFound = SelectionRangeWithItems.Empty; for (int i = 0; i < count; i++) { SelectionRangeWithItems rangeWithItems = m_list[i]; indexOffset += rangeWithItems.Length; if (index < indexOffset) { rangeWithItemsFound = rangeWithItems; // .GetItem( dataGridContext, index - oldIndexOffset ); break; } oldIndexOffset = indexOffset; } if (!rangeWithItemsFound.IsEmpty) { DataGridContext dataGridContext = m_list.DataGridContext; SelectionManager selectionManager = dataGridContext.DataGridControl.SelectionChangerManager; selectionManager.Begin(); try { selectionManager.UnselectItems(dataGridContext, new SelectionRangeWithItems( rangeWithItemsFound.Range.GetIndexFromItemOffset(index - oldIndexOffset), rangeWithItemsFound.GetItem(dataGridContext, index - oldIndexOffset))); } finally { selectionManager.End(false, true, true); } } }
public void Visit(DataGridContext sourceContext, int startSourceDataItemIndex, int endSourceDataItemIndex, ref bool stopVisit) { SelectionManager selectionChangerManager = sourceContext.DataGridControl.SelectionChangerManager; if (m_selectedColumns != null) { int columnCount = sourceContext.Columns.Count; if (columnCount == 0) { return; } SelectionRange contextColumnMaxRange = new SelectionRange(0, columnCount - 1); for (int i = 0; i < m_selectedColumns.Length; i++) { SelectionRange selectionRange = m_selectedColumns[i]; SelectionRange intersectionSelectionRange = selectionRange.Intersect(contextColumnMaxRange); if (intersectionSelectionRange.IsEmpty) { continue; } #if DEBUG string action = (m_unselect) ? "Removing" : "Adding"; Debug.WriteLine("Selection : " + action + " cell : (" + startSourceDataItemIndex.ToString() + " - " + endSourceDataItemIndex.ToString() + ") - (" + intersectionSelectionRange.StartIndex.ToString() + " - " + intersectionSelectionRange.EndIndex.ToString() + ")"); #endif var cellRange = new SelectionCellRangeWithItems(new SelectionRange(startSourceDataItemIndex, endSourceDataItemIndex), null, intersectionSelectionRange); if (m_unselect) { selectionChangerManager.UnselectCells(sourceContext, cellRange); } else { selectionChangerManager.SelectCells(sourceContext, cellRange); } } } else { #if DEBUG string action = (m_unselect) ? "Removing" : "Adding"; Debug.WriteLine("Selection : " + action + " Adding item : " + startSourceDataItemIndex.ToString() + " - " + endSourceDataItemIndex.ToString()); #endif var itemRange = new SelectionRangeWithItems(new SelectionRange(startSourceDataItemIndex, endSourceDataItemIndex), null); if (m_unselect) { selectionChangerManager.UnselectItems(sourceContext, itemRange); } else { selectionChangerManager.SelectItems(sourceContext, itemRange); } } }
internal SelectionRangeWithItemsWrapper(SelectionRangeWithItems value, int index) { m_value = value; m_index = index; }