internal void MoveCurrentTo(object item, int backupSlot, int columnIndex, DataGridSelectionAction action, bool scrollIntoView) { if (CollectionView != null) { _expectingCurrentChanged = true; _columnForCurrentChanged = columnIndex; _itemToSelectOnCurrentChanged = item; _selectionActionForCurrentChanged = action; _scrollForCurrentChanged = scrollIntoView; _backupSlotForCurrentChanged = backupSlot; CollectionView.MoveCurrentTo(item is DataGridCollectionViewGroup ? null : item); _expectingCurrentChanged = false; } }
internal void MoveCurrentTo(object item, int backupSlot, int columnIndex, DataGridSelectionAction action, bool scrollIntoView) { if (this.CollectionView != null) { _expectingCurrentChanged = true; _columnForCurrentChanged = columnIndex; _itemToSelectOnCurrentChanged = item; _selectionActionForCurrentChanged = action; _scrollForCurrentChanged = scrollIntoView; _backupSlotForCurrentChanged = backupSlot; var itemIsCollectionViewGroup = item is ICollectionViewGroup; this.CollectionView.MoveCurrentTo((itemIsCollectionViewGroup || this.IndexOf(item) == this.NewItemPlaceholderIndex) ? null : item); _expectingCurrentChanged = false; } }
internal bool UpdateSelectionAndCurrency(int columnIndex, int slot, DataGridSelectionAction action, bool scrollIntoView) { this._successfullyUpdatedSelection = false; this._noSelectionChangeCount++; this._noCurrentCellChangeCount++; try { if (this.ColumnsInternal.RowGroupSpacerColumn.IsRepresented && columnIndex == this.ColumnsInternal.RowGroupSpacerColumn.Index) { columnIndex = -1; } if (IsSlotOutOfSelectionBounds(slot) || (columnIndex != -1 && IsColumnOutOfBounds(columnIndex))) { return false; } int newCurrentPosition = -1; object item = ItemFromSlot(slot, ref newCurrentPosition); if (this.EditingRow != null && slot != this.EditingRow.Slot && !CommitEdit(DataGridEditingUnit.Row, true)) { return false; } if (this.DataConnection.CollectionView != null && this.DataConnection.CollectionView.CurrentPosition != newCurrentPosition) { this.DataConnection.MoveCurrentTo(item, slot, columnIndex, action, scrollIntoView); } else { this.ProcessSelectionAndCurrency(columnIndex, item, slot, action, scrollIntoView); } } finally { this.NoCurrentCellChangeCount--; this.NoSelectionChangeCount--; } return this._successfullyUpdatedSelection; }
internal void MoveCurrentTo(object item, int backupSlot, int columnIndex, DataGridSelectionAction action, bool scrollIntoView) { if (this.CollectionView != null) { this._expectingCurrentChanged = true; this._columnForCurrentChanged = columnIndex; this._itemToSelectOnCurrentChanged = item; this._selectionActionForCurrentChanged = action; this._scrollForCurrentChanged = scrollIntoView; this._backupSlotForCurrentChanged = backupSlot; this.CollectionView.MoveCurrentTo(item is CollectionViewGroup ? null : item); this._expectingCurrentChanged = false; } }
/// <summary> /// Selects items and updates currency based on parameters /// </summary> /// <param name="columnIndex">column index to make current</param> /// <param name="item">data item or CollectionViewGroup to make current</param> /// <param name="backupSlot">slot to use in case the item is no longer valid</param> /// <param name="action">selection action to perform</param> /// <param name="scrollIntoView">whether or not the new current item should be scrolled into view</param> internal void ProcessSelectionAndCurrency(int columnIndex, object item, int backupSlot, DataGridSelectionAction action, bool scrollIntoView) { this._noSelectionChangeCount++; this._noCurrentCellChangeCount++; try { int slot = -1; CollectionViewGroup group = item as CollectionViewGroup; if (group != null) { DataGridRowGroupInfo groupInfo = this.RowGroupInfoFromCollectionViewGroup(group); if (groupInfo != null) { slot = groupInfo.Slot; } } else { slot = this.SlotFromRowIndex(this.DataConnection.IndexOf(item)); } if (slot == -1) { slot = backupSlot; } if (slot < 0 || slot > this.SlotCount) { return; } switch (action) { case DataGridSelectionAction.AddCurrentToSelection: SetRowSelection(slot, true /*isSelected*/, true /*setAnchorIndex*/); break; case DataGridSelectionAction.RemoveCurrentFromSelection: SetRowSelection(slot, false /*isSelected*/, false /*setAnchorRowIndex*/); break; case DataGridSelectionAction.SelectFromAnchorToCurrent: if (this.SelectionMode == DataGridSelectionMode.Extended && this.AnchorSlot != -1) { int anchorSlot = this.AnchorSlot; ClearRowSelection(slot /*slotException*/, false /*resetAnchorSlot*/); if (slot <= anchorSlot) { SetRowsSelection(slot, anchorSlot); } else { SetRowsSelection(anchorSlot, slot); } } else { goto case DataGridSelectionAction.SelectCurrent; } break; case DataGridSelectionAction.SelectCurrent: ClearRowSelection(slot /*rowIndexException*/, true /*setAnchorRowIndex*/); break; case DataGridSelectionAction.None: break; } if (this.CurrentSlot != slot || (this.CurrentColumnIndex != columnIndex && columnIndex != -1)) { if (columnIndex == -1) { if (this.CurrentColumnIndex != -1) { columnIndex = this.CurrentColumnIndex; } else { DataGridColumn firstVisibleColumn = this.ColumnsInternal.FirstVisibleNonFillerColumn; if (firstVisibleColumn != null) { columnIndex = firstVisibleColumn.Index; } } } if (columnIndex != -1) { if (!SetCurrentCellCore(columnIndex, slot, true /*commitEdit*/, SlotFromRowIndex(this.SelectedIndex) != slot /*endRowEdit*/) || (scrollIntoView && !ScrollSlotIntoView(columnIndex, slot, true /*forCurrentCellChange*/, false /*forceHorizontalScroll*/))) { return; } } } this._successfullyUpdatedSelection = true; } finally { this.NoCurrentCellChangeCount--; this.NoSelectionChangeCount--; } }