protected override void InsertItem(int columnIndex, DataGridColumn dataGridColumn)
        {
            Debug.Assert(_owningGrid != null, "Expected non-null owning DataGrid.");
            try
            {
                _owningGrid.NoCurrentCellChangeCount++;
                if (_owningGrid.InDisplayIndexAdjustments)
                {
                    // We are within columns display indexes adjustments. We do not allow changing the column collection while adjusting display indexes.
                    throw DataGridError.DataGrid.CannotChangeColumnCollectionWhileAdjustingDisplayIndexes();
                }

                if (dataGridColumn == null)
                {
                    throw new ArgumentNullException("dataGridColumn");
                }

                int columnIndexWithFiller = columnIndex;
                if (dataGridColumn != this.RowGroupSpacerColumn && this.RowGroupSpacerColumn.IsRepresented)
                {
                    columnIndexWithFiller++;
                }

                // get the new current cell coordinates
                DataGridCellCoordinates newCurrentCellCoordinates = _owningGrid.OnInsertingColumn(columnIndex, dataGridColumn);

                // insert the column into our internal list
                this.ItemsInternal.Insert(columnIndexWithFiller, dataGridColumn);
                dataGridColumn.Index      = columnIndexWithFiller;
                dataGridColumn.OwningGrid = _owningGrid;
                dataGridColumn.RemoveEditingElement();
                if (dataGridColumn.IsVisible)
                {
                    this.VisibleEdgedColumnsWidth += dataGridColumn.ActualWidth;
                }

                // continue with the base insert
                _owningGrid.OnInsertedColumn_PreNotification(dataGridColumn);
                _owningGrid.OnColumnCollectionChanged_PreNotification(true /*columnsGrew*/);

                if (dataGridColumn != this.RowGroupSpacerColumn)
                {
                    base.InsertItem(columnIndex, dataGridColumn);
                }

                _owningGrid.OnInsertedColumn_PostNotification(newCurrentCellCoordinates, dataGridColumn.DisplayIndex);
                _owningGrid.OnColumnCollectionChanged_PostNotification(true /*columnsGrew*/);
            }
            finally
            {
                _owningGrid.NoCurrentCellChangeCount--;
            }
        }
        private void RemoveItemPrivate(int columnIndex, bool isSpacer)
        {
            Debug.Assert(_owningGrid != null, "Expected non-null owning DataGrid.");
            try
            {
                _owningGrid.NoCurrentCellChangeCount++;

                if (_owningGrid.InDisplayIndexAdjustments)
                {
                    // We are within columns display indexes adjustments. We do not allow changing the column collection while adjusting display indexes.
                    throw DataGridError.DataGrid.CannotChangeColumnCollectionWhileAdjustingDisplayIndexes();
                }

                int columnIndexWithFiller = columnIndex;
                if (!isSpacer && this.RowGroupSpacerColumn.IsRepresented)
                {
                    columnIndexWithFiller++;
                }

                Debug.Assert(columnIndexWithFiller >= 0 && columnIndexWithFiller < this.ItemsInternal.Count, "Unexpected columnIndexWithFiller value.");

                DataGridColumn          dataGridColumn            = this.ItemsInternal[columnIndexWithFiller];
                DataGridCellCoordinates newCurrentCellCoordinates = _owningGrid.OnRemovingColumn(dataGridColumn);
                this.ItemsInternal.RemoveAt(columnIndexWithFiller);
                if (dataGridColumn.IsVisible)
                {
                    this.VisibleEdgedColumnsWidth -= dataGridColumn.ActualWidth;
                }

                dataGridColumn.OwningGrid = null;
                dataGridColumn.RemoveEditingElement();

                // continue with the base remove
                _owningGrid.OnRemovedColumn_PreNotification(dataGridColumn);
                _owningGrid.OnColumnCollectionChanged_PreNotification(false /*columnsGrew*/);
                if (!isSpacer)
                {
                    base.RemoveItem(columnIndex);
                }

                _owningGrid.OnRemovedColumn_PostNotification(newCurrentCellCoordinates);
                _owningGrid.OnColumnCollectionChanged_PostNotification(false /*columnsGrew*/);
            }
            finally
            {
                _owningGrid.NoCurrentCellChangeCount--;
            }
        }
Пример #3
0
        internal DataGridCellCoordinates OnRemovingColumn(DataGridColumnBase dataGridColumn)
        {
            Debug.Assert(dataGridColumn != null); 
            Debug.Assert(dataGridColumn.Index >= 0 && dataGridColumn.Index < this.ColumnsItemsInternal.Count);

            DataGridCellCoordinates newCurrentCellCoordinates; 
 
            this._temporarilyResetCurrentCell = false;
            int columnIndex = dataGridColumn.Index; 

            // Trash all recyclable rows
            this._recyclableRows.Clear(); 

            // Reset the current cell's address if there is one.
            if (this.CurrentColumnIndex != -1) 
            { 
                int newCurrentColumnIndex = this.CurrentColumnIndex;
                if (columnIndex == newCurrentColumnIndex) 
                {
                    DataGridColumnBase dataGridColumnNext = this.ColumnsInternal.GetNextVisibleColumn(this.ColumnsItemsInternal[columnIndex]);
                    if (dataGridColumnNext != null) 
                    {
                        if (dataGridColumnNext.Index > columnIndex)
                        { 
                            newCurrentColumnIndex = dataGridColumnNext.Index - 1; 
                        }
                        else 
                        {
                            newCurrentColumnIndex = dataGridColumnNext.Index;
                        } 
                    }
                    else
                    { 
                        DataGridColumnBase dataGridColumnPrevious = this.ColumnsInternal.GetPreviousVisibleColumn(this.ColumnsItemsInternal[columnIndex]); 
                        if (dataGridColumnPrevious != null)
                        { 
                            if (dataGridColumnPrevious.Index > columnIndex)
                            {
                                newCurrentColumnIndex = dataGridColumnPrevious.Index - 1; 
                            }
                            else
                            { 
                                newCurrentColumnIndex = dataGridColumnPrevious.Index; 
                            }
                        } 
                        else
                        {
                            newCurrentColumnIndex = -1; 
                        }
                    }
                } 
                else if (columnIndex < newCurrentColumnIndex) 
                {
                    newCurrentColumnIndex--; 
                }
                newCurrentCellCoordinates = new DataGridCellCoordinates(newCurrentColumnIndex, (newCurrentColumnIndex == -1) ? -1 : this.CurrentRowIndex);
                if (columnIndex == this.CurrentColumnIndex) 
                {
                    // Left cell is not validated since cancelling validation wouldn't have any effect anyways.
                    bool success = SetCurrentCellCore(-1, -1/* */); 
                    Debug.Assert(success); 
                }
                else // 
                {
                    // Underlying data of deleted column is gone. It cannot be accessed anymore.
                    // Do not end editing mode so that CellValidation doesn't get raised, since that event needs the current formatted value. 
                    this._temporarilyResetCurrentCell = true;
                    bool success = SetCurrentCellCore(-1, -1/* */);
                    Debug.Assert(success); 
                } 
                //
 


 

            }
            else 
            { 
                newCurrentCellCoordinates = new DataGridCellCoordinates(-1, -1);
            } 

            // If the last column is removed, delete all the rows first.
            if (this.ColumnsItemsInternal.Count == 1) 
            {
                ClearRows();
            } 
            else 
            {
                // Removing the potential vertical gridlines 
                RemoveDisplayedVerticalGridlines(dataGridColumn);
            }
 
            // Is deleted column scrolled off screen?
            if (dataGridColumn.Visibility == Visibility.Visible &&
                !dataGridColumn.IsFrozen && 
                this.DisplayData.FirstDisplayedScrollingCol >= 0) 
            {
                // Deleted column is part of scrolling columns. 
                if (this.DisplayData.FirstDisplayedScrollingCol == dataGridColumn.Index)
                {
                    // Deleted column is first scrolling column 
                    this._horizontalOffset -= this._negHorizontalOffset;
                    this._negHorizontalOffset = 0;
                } 
                else if (!this.ColumnsInternal.DisplayInOrder(this.DisplayData.FirstDisplayedScrollingCol, dataGridColumn.Index)) 
                {
                    // Deleted column is displayed before first scrolling column 
                    Debug.Assert(this._horizontalOffset >= GetEdgedColumnWidth(dataGridColumn));
                    this._horizontalOffset -= GetEdgedColumnWidth(dataGridColumn);
                } 

                if (this._hScrollBar != null && this._hScrollBar.Visibility == Visibility.Visible) //
                { 
                    this._hScrollBar.Value = this._horizontalOffset; 
                }
            } 

            return newCurrentCellCoordinates;
        } 
Пример #4
0
 internal void OnRemovedColumn_PostNotification(DataGridCellCoordinates newCurrentCellCoordinates)
 { 
     // Update current cell if needed
     if (newCurrentCellCoordinates.ColumnIndex != -1)
     { 
         Debug.Assert(this.CurrentColumnIndex == -1); 
         bool success = SetAndSelectCurrentCell(newCurrentCellCoordinates.ColumnIndex,
                                                newCurrentCellCoordinates.RowIndex, 
                                                false /*forceCurrentCellSelection*/);
         Debug.Assert(success);
     } 
 }
Пример #5
0
        internal DataGridCellCoordinates OnInsertingColumn(int columnIndexInserted, DataGridColumnBase insertColumn)
        { 
            DataGridCellCoordinates newCurrentCellCoordinates;
            Debug.Assert(insertColumn != null);
 
            if (insertColumn.OwningGrid != null)
            {
                throw DataGridError.DataGrid.ColumnCannotBeReassignedToDifferentDataGrid(); 
            } 

            // Trash all recyclable rows 
            this._recyclableRows.Clear();

            // check for correctness of frozen state - throws exception if state is incorrect. 
            CorrectColumnFrozenState(insertColumn, columnIndexInserted);

            // Reset current cell if there is one, no matter the relative position of the columns involved 
            if (this.CurrentColumnIndex != -1) 
            {
                newCurrentCellCoordinates = new DataGridCellCoordinates(columnIndexInserted <= this.CurrentColumnIndex ? this.CurrentColumnIndex + 1 : this.CurrentColumnIndex, 
                     this.CurrentRowIndex);
                ResetCurrentCellCore();
            } 
            else
            {
                newCurrentCellCoordinates = new DataGridCellCoordinates(-1, -1); 
            } 
            return newCurrentCellCoordinates;
        } 
Пример #6
0
        internal void InsertRows(int rowIndex, int rowCount)
        { 
            Debug.Assert(this.ColumnsItemsInternal.Count > 0);
            Debug.Assert(rowIndex >= 0 && rowIndex <= this._rowCount);
            Debug.Assert(rowCount == 1); 

            if (RowRequiresDisplay(rowIndex))
            { 
                // Row at that index needs to be displayed 
                InsertRow(rowIndex);
            } 
            else
            {
                // Row at that index is off screen 
                DataGridCellCoordinates newCurrentCellCoordinates = new DataGridCellCoordinates(-1, -1);
                OnInsertingRow(rowIndex, ref newCurrentCellCoordinates, true /*firstInsertion*/, 1 /*insertionCount*/);   // will throw an exception if the insertion is illegal
                this._rowCount++; 
                OnInsertedRow_Phase1(rowIndex, false /*generateRow*/, 1); 
                OnInsertedRow_Phase2(rowIndex, newCurrentCellCoordinates, true /*lastInsertion*/,
                    this._vScrollBar == null || this._vScrollBar.Visibility == Visibility.Visible /*updateVerticalScrollBarOnly*/); 
                OnRowsChanged(true /*rowsGrew*/);
            }
        }