public DataGridCellEditingCancelEventArgs(DataGridColumnBase dataGridColumn, 
                                           DataGridRow dataGridRow,
                                           FrameworkElement element,
                                           DataGridEditingTriggerInfo editingTriggerInfo) : base(dataGridColumn, dataGridRow, element) 
 {
     this.EditingTriggerInfo = editingTriggerInfo;
 } 
 public DataGridCellEditingCancelEventArgs(DataGridColumnBase dataGridColumn,
                                           DataGridRow dataGridRow,
                                           FrameworkElement element,
                                           DataGridEditingTriggerInfo editingTriggerInfo) : base(dataGridColumn, dataGridRow, element)
 {
     this.EditingTriggerInfo = editingTriggerInfo;
 }
Example #3
0
 public DataGridPrepareCellEditEventArgs(DataGridColumnBase dataGridColumn,
                                         DataGridRow dataGridRow,
                                         Control element,
                                         DataGridEditingTriggerInfo editingTriggerInfo) : base(dataGridColumn, dataGridRow, element)
 {
     this.EditingTriggerInfo = editingTriggerInfo;
 }
Example #4
0
 private void OnRemoveFirstColumn(object sender, RoutedEventArgs e)
 {
     if (DataGrid.Columns.Count > 0)
     {
         _removedColumn = DataGrid.Columns.First();
         DataGrid.Columns.Remove(_removedColumn);
     }
 }
Example #5
0
 public DataGridColumnEventArgs(DataGridColumnBase column)
 {
     if (column == null)
     {
         throw new ArgumentNullException("column");
     }
     this.Column = column;
 }
Example #6
0
 public DataGridColumnEventArgs(DataGridColumnBase column) 
 {
     if (column == null)
     { 
         throw new ArgumentNullException("column");
     }
     this.Column = column; 
 } 
Example #7
0
 private void OnAddRemovedColumn(object sender, RoutedEventArgs e)
 {
     if (_removedColumn != null)
     {
         DataGrid.Columns.Add(_removedColumn);
         _removedColumn = null;
     }
 }
Example #8
0
 //Gets inventory data from database and sets it as the datagrid's source.
 private void UpdateTable()
 {
     if (DataGrid.SelectedColumn != null)
     {
         DataGridColumnBase Column = DataGrid.SelectedColumn;
         DataGrid.ItemsSource = Item.Table;
         DataGrid.SelectColumn(Column);
         DataGrid.SelectColumn(Column);
     }
     else
     {
         DataGrid.ItemsSource = Item.Table;
     }
 }
Example #9
0
        public DataGridDataErrorEventArgs(Exception exception,
                                          DataGridColumnBase dataGridColumn,
                                          DataGridRow dataGridRow)
        {
            if (dataGridColumn == null)
            {
                throw new ArgumentNullException("dataGridColumn");
            }
            //



            this.Column    = dataGridColumn;
            this.Row       = dataGridRow;
            this.Exception = exception;
        }
Example #10
0
        public DataGridDataErrorEventArgs(Exception exception, 
                                          DataGridColumnBase dataGridColumn, 
                                          DataGridRow dataGridRow)
        { 
            if (dataGridColumn == null)
            {
                throw new ArgumentNullException("dataGridColumn"); 
            }
            //
 
 

 

            this.Column = dataGridColumn;
            this.Row = dataGridRow; 
            this.Exception = exception;
        }
Example #11
0
 public DataGridCellEventArgs(DataGridColumnBase dataGridColumn,
                              DataGridRow dataGridRow, 
                              FrameworkElement element)
 {
     if (dataGridColumn == null) 
     { 
         throw new ArgumentNullException("dataGridColumn");
     } 
     if (dataGridRow == null)
     {
         throw new ArgumentNullException("dataGridRow"); 
     }
     if (element == null)
     { 
         throw new ArgumentNullException("element"); 
     }
     this.Column = dataGridColumn; 
     this.Row = dataGridRow;
     this.Element = element;
 } 
Example #12
0
        internal bool GetColumnReadOnlyState(DataGridColumnBase dataGridColumn, bool isReadOnly) 
        { 
            Debug.Assert(dataGridColumn != null);
 
            DataGridBoundColumnBase dataGridBoundColumn = dataGridColumn as DataGridBoundColumnBase;
            if (dataGridBoundColumn != null && !string.IsNullOrEmpty(dataGridBoundColumn.DisplayMemberPath))
            { 
                if (dataGridBoundColumn.DisplayMemberBinding != null
                    && dataGridBoundColumn.DisplayMemberBinding.Converter != null
                    && dataGridBoundColumn.DisplayMemberBinding.Converter is DataGridValueConverter) 
                { 
                    if (!DataGridValueConverter.CanEdit(dataGridBoundColumn.Type))
                    { 
                        return true;
                    }
                } 

                return this.DataConnection.GetPropertyIsReadOnly(dataGridBoundColumn.DisplayMemberPath) || isReadOnly;
            } 
 
            return isReadOnly;
        } 
Example #13
0
        internal void OnColumnDisplayIndexChanged(DataGridColumnBase dataGridColumn)
        { 
            Debug.Assert(dataGridColumn != null);
            DataGridColumnEventArgs e = new DataGridColumnEventArgs(dataGridColumn);
 
            // Call protected method to raise event
            OnColumnDisplayIndexChanged(e);
        } 
Example #14
0
        private static void UpdateCellElement(DataGridColumnBase dataGridColumn, DataGridRow dataGridRow, string propertyName) 
        {
            Debug.Assert(dataGridColumn != null);
            Debug.Assert(dataGridRow != null); 

            DataGridCell dataGridCell = dataGridRow.Cells[dataGridColumn.Index];
            Debug.Assert(dataGridCell != null); 
            FrameworkElement element = dataGridCell.Content as FrameworkElement; 
            if (element != null)
            { 
                dataGridColumn.UpdateElement(element, propertyName);
            }
        } 
Example #15
0
 public DataGridCellCancelEventArgs(DataGridColumnBase dataGridColumn,
                                    DataGridRow dataGridRow,
                                    FrameworkElement element) : base(dataGridColumn, dataGridRow, element)
 {
 }
Example #16
0
        /// <summary>
        /// Called when a column property changes, and its cells need to 
        /// adjust that that column change. 
        /// </summary>
        internal void UpdateColumnElements(DataGridColumnBase dataGridColumn, string propertyName) 
        {
            Debug.Assert(dataGridColumn != null);
 
            //

 
 
            // Take care of the non-displayed prepared rows
            for (int index = 0; index < this._preparedRows.Count; ) 
            {
                DataGridRow dataGridRow = this._preparedRows[index];
                Debug.Assert(dataGridRow != null); 
                if (!IsRowDisplayed(dataGridRow.Index))
                {
                    UpdateCellElement(dataGridColumn, dataGridRow, propertyName); 
                } 
                index++;
            } 

            // Take care of the non-displayed edited row
            if (this._editingRow != null && !IsRowDisplayed(this._editingRow.Index)) 
            {
                UpdateCellElement(dataGridColumn, this._editingRow, propertyName);
            } 
 
            // Take care of the displayed rows
            if (this._cells != null) 
            {
                for (int childIndex = 0; childIndex < this.DisplayedRowCount; childIndex++)
                { 
                    UpdateCellElement(dataGridColumn, GetDisplayedRow(this._firstDisplayedRowIndex + childIndex), propertyName);
                }
            } 
        } 
Example #17
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;
        } 
Example #18
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;
        } 
Example #19
0
        internal void OnColumnVisibleStateChanging(DataGridColumnBase targetColumn)
        { 
            Debug.Assert(targetColumn != null);

            if (targetColumn.Visibility == Visibility.Visible && 
                this.CurrentColumn == targetColumn) 
            {
                // Column of the current cell is made invisible. Trying to move the current cell to a neighbor column. May throw an exception. 
                DataGridColumnBase dataGridColumn = this.ColumnsInternal.GetNextVisibleColumn(targetColumn);
                if (dataGridColumn == null)
                { 
                    dataGridColumn = this.ColumnsInternal.GetPreviousVisibleColumn(targetColumn);
                }
                if (dataGridColumn == null) 
                { 
                    SetCurrentCellCore(-1, -1);
                } 
                else
                {
                    SetCurrentCellCore(dataGridColumn.Index, this.CurrentRowIndex); 
                }
            }
 
            CorrectColumnFrozenStates(targetColumn, false); 
        }
Example #20
0
        // 
 

 


        internal void OnColumnReadOnlyStateChanging(DataGridColumnBase dataGridColumn, bool isReadOnly) 
        {
            Debug.Assert(dataGridColumn != null);
            DataGridBoundColumnBase dataGridBoundColumn = dataGridColumn as DataGridBoundColumnBase; 
            if (!isReadOnly && !string.IsNullOrEmpty(dataGridBoundColumn.DisplayMemberPath)) 
            {
                if (this.DataConnection.GetPropertyIsReadOnly(dataGridBoundColumn.DisplayMemberPath)) 
                {
                    // Cannot set a column to read/write when the backend does not allow it.
                    throw DataGridError.DataGrid.UnderlyingPropertyIsReadOnly(); 
                }
            }
            if (isReadOnly && this.CurrentColumnIndex == dataGridColumn.Index) 
            { 
                // Edited column becomes read-only. Exit editing mode.
                if (!EndCellEdit(true /*commitCellEdit*/, true /*exitEditingMode*/, this.ContainsFocus /*keepFocus*/)) 
                {
                    throw DataGridError.DataGrid.CommitFailedCannotCompleteOperation();
                } 
            }
        }
Example #21
0
 internal bool ColumnRequiresRightGridline(DataGridColumnBase dataGridColumn, bool includeLastRightGridlineWhenPresent)
 {
     return (this.GridlinesVisibility == DataGridGridlines.Vertical || this.GridlinesVisibility == DataGridGridlines.All) && this.VerticalGridlinesBrush != null /*&& this.VerticalGridlinesThickness > 0*/ && 
            (dataGridColumn != this.ColumnsInternal.LastVisibleColumn || (includeLastRightGridlineWhenPresent && this.ColumnsInternal.FillerColumn.IsActive)); 
 }
Example #22
0
        internal void OnColumnDisplayIndexChanging(DataGridColumnBase targetColumn, int newDisplayIndex) 
        { 
            Debug.Assert(targetColumn != null);
            Debug.Assert(newDisplayIndex != targetColumn.DisplayIndex); 

            if (InDisplayIndexAdjustments)
            { 
                // We are within columns display indexes adjustments. We do not allow changing display indexes while adjusting them.
                throw DataGridError.DataGrid.CannotChangeColumnCollectionWhileAdjustingDisplayIndexes();
            } 
 
            // Throws an exception if the requested move is illegal
            CorrectColumnFrozenStatesForMove(targetColumn, newDisplayIndex); 

            try
            { 

                InDisplayIndexAdjustments = true;
 
                // Move is legal - let's adjust the affected display indexes. 
                if (newDisplayIndex < targetColumn.DisplayIndex)
                { 
                    // DisplayIndex decreases. All columns with newDisplayIndex <= DisplayIndex < targetColumn.DisplayIndex
                    // get their DisplayIndex incremented.
                    foreach (DataGridColumnBase column in this.Columns) 
                    {
                        if (newDisplayIndex <= column.DisplayIndex && column.DisplayIndex < targetColumn.DisplayIndex)
                        { 
                            column.DisplayIndexInternal = column.DisplayIndex + 1; 
                            column.DisplayIndexHasChanged = true; // OnColumnDisplayIndexChanged needs to be raised later on
                        } 
                    }
                }
                else 
                {
                    // DisplayIndex increases. All columns with targetColumn.DisplayIndex < DisplayIndex <= newDisplayIndex
                    // get their DisplayIndex incremented. 
                    foreach (DataGridColumnBase column in this.Columns) 
                    {
                        if (targetColumn.DisplayIndex < column.DisplayIndex && column.DisplayIndex <= newDisplayIndex) 
                        {
                            column.DisplayIndexInternal = column.DisplayIndex - 1;
                            column.DisplayIndexHasChanged = true; // OnColumnDisplayIndexChanged needs to be raised later on 
                        }
                    }
                } 
            } 
            finally
            { 
                InDisplayIndexAdjustments = false;
            }
 
            // Note that displayIndex of moved column is updated by caller.
        }
Example #23
0
        internal void OnColumnFrozenStateChanged(DataGridColumnBase updatedColumn) 
        {
            Debug.Assert(updatedColumn != null);
            if (updatedColumn.Visibility == Visibility.Visible) 
            { 
                if (updatedColumn.IsFrozen)
                { 
                    // visible column became frozen
                    if (this._horizontalOffset >= GetEdgedColumnWidth(updatedColumn))
                    { 
                        Debug.Assert(this.ColumnsInternal.DisplayInOrder(updatedColumn.Index, this.DisplayData.FirstDisplayedScrollingCol));
                        this._horizontalOffset -= GetEdgedColumnWidth(updatedColumn);
                    } 
                    else 
                    {
                        this._horizontalOffset = this._negHorizontalOffset = 0; 
                    }
                }
                else 
                {
                    // column was unfrozen - make it the first visible scrolling column if there is room
                    this._horizontalOffset = this._negHorizontalOffset = 0; 
                } 
                //
 


 

                PerformLayout();
            } 
        } 
Example #24
0
        private void CorrectColumnFrozenState(DataGridColumnBase targetColumn, int anticipatedColumnIndex) 
        {
            Debug.Assert(targetColumn != null);
            Debug.Assert(anticipatedColumnIndex >= 0 && anticipatedColumnIndex <= this.ColumnsItemsInternal.Count); 

            int anticipatedColumnDisplayIndex;
            if (targetColumn.DisplayIndex == -1 || targetColumn.DisplayIndex > this.ColumnsItemsInternal.Count) 
            { 
                anticipatedColumnDisplayIndex = anticipatedColumnIndex; // By default, we pick the Index as the DisplayIndex.
            } 
            else
            {
                Debug.Assert(targetColumn.DisplayIndex >= 0 && targetColumn.DisplayIndex <= this.ColumnsItemsInternal.Count); 
                anticipatedColumnDisplayIndex = targetColumn.DisplayIndex; // The specified DisplayIndex is just fine.
            }
 
            DataGridColumnBase previousColumn; 
            int displayIndex = anticipatedColumnDisplayIndex - 1;
            do 
            {
                previousColumn = this.ColumnsInternal.GetColumnAtDisplayIndex(displayIndex);
                displayIndex--; 
            }
            while (displayIndex >= 0 && (previousColumn == null || previousColumn.Visibility == Visibility.Collapsed));
            if (previousColumn != null && !previousColumn.IsFrozen && targetColumn.IsFrozen) 
            { 
                throw DataGridError.DataGrid.CannotAddNonFrozenColumn();
            } 
            else
            {
                DataGridColumnBase nextColumn; 
                displayIndex = anticipatedColumnDisplayIndex;
                do
                { 
                    nextColumn = this.ColumnsInternal.GetColumnAtDisplayIndex(displayIndex); 
                    displayIndex++;
                } 
                while (displayIndex < this.ColumnsItemsInternal.Count && (nextColumn == null || nextColumn.Visibility == Visibility.Collapsed));
                if (nextColumn != null && nextColumn.IsFrozen && !targetColumn.IsFrozen)
                { 
                    throw DataGridError.DataGrid.CannotAddNonFrozenColumn();
                }
            } 
        } 
Example #25
0
 internal void OnColumnFrozenStateChanging(DataGridColumnBase targetColumn) 
 {
     Debug.Assert(targetColumn != null);
     CorrectColumnFrozenStates(targetColumn, true); 
 }
Example #26
0
 private void CorrectColumnFrozenStates(DataGridColumnBase targetColumn, bool frozenStateChanging) 
 {
     Debug.Assert(targetColumn != null);
     DataGridColumnBase column; 
     if ((targetColumn.IsFrozen && !frozenStateChanging) ||
         (!targetColumn.IsFrozen && frozenStateChanging))
     { 
         // make sure the previous visible columns are frozen as well 
         column = this.ColumnsInternal.GetPreviousVisibleFrozenColumn(targetColumn);
         if (column == null) 
         {
             DataGridColumnBase firstVisibleColumn = this.ColumnsInternal.FirstVisibleColumn;
             if (firstVisibleColumn != targetColumn) 
             {
                 column = firstVisibleColumn;
             } 
         } 
         while (column != null && this.ColumnsInternal.DisplayInOrder(column.Index, targetColumn.Index))
         { 
             column.IsFrozen = true;
             column = this.ColumnsInternal.GetNextVisibleScrollingColumn(column);
         } 
     }
     else
     { 
         // make sure the next visible columns are not frozen 
         column = this.ColumnsInternal.GetNextVisibleScrollingColumn(targetColumn);
         if (column == null) 
         {
             DataGridColumnBase lastColumn = targetColumn;
             do 
             {
                 column = this.ColumnsInternal.GetNextVisibleColumn(lastColumn);
                 if (column != null) 
                 { 
                     lastColumn = column;
                 } 
             }
             while (column != null);
             if (lastColumn != targetColumn) 
             {
                 column = lastColumn;
             } 
         } 
         while (column != null && this.ColumnsInternal.DisplayInOrder(targetColumn.Index, column.Index))
         { 
             column.IsFrozen = false;
             column = this.ColumnsInternal.GetPreviousVisibleFrozenColumn(column);
         } 
     }
 }
Example #27
0
        internal void OnColumnVisibleStateChanged(DataGridColumnBase updatedColumn) 
        {
            Debug.Assert(updatedColumn != null); 
            //

            UpdateColumnHeadersSeparatorVisibility(); 
            PerformLayout();
            if (updatedColumn.Visibility == Visibility.Visible &&
                this.ColumnsInternal.VisibleColumnCount == 1 && this.CurrentColumnIndex == -1) 
            { 
                DataGridRow dataGridRow = GetRowFromItem(this.SelectedItem);
                if (dataGridRow != null) 
                {
                    SetAndSelectCurrentCell(updatedColumn.Index, dataGridRow.Index, true /*forceCurrentCellSelection*/);
                } 
                else
                {
                    MakeFirstDisplayedCellCurrentCell(); 
                } 
            }
        } 
Example #28
0
        // This method checks to see if the column moving is frozen or if the column is moving into a group 
        // of frozen columns.  It throws an exception in both cases.
        private void CorrectColumnFrozenStatesForMove(DataGridColumnBase targetColumn, int newDisplayIndex) 
        {
            Debug.Assert(targetColumn != null);
            Debug.Assert(newDisplayIndex != targetColumn.DisplayIndex); 
            Debug.Assert(!InDisplayIndexAdjustments);

            // No check necessary when: 
            // - column is invisible. 
            // - DisplayIndex decreases and column is frozen.
            // - DisplayIndex increases and column is unfrozen. 

            if (targetColumn.Visibility == Visibility.Collapsed ||
                (newDisplayIndex < targetColumn.DisplayIndex && targetColumn.IsFrozen) || 
                (newDisplayIndex > targetColumn.DisplayIndex && !targetColumn.IsFrozen))
            {
                return; 
            } 

            int colCount = this.ColumnsItemsInternal.Count, displayIndex; 

            if (newDisplayIndex < targetColumn.DisplayIndex)
            { 
                // DisplayIndex decreases.
                // Throw an exception if the visible unfrozen column is placed before a frozen column
                // Get the closest visible column placed after the displaced column 
                DataGridColumnBase nextColumn; 
                displayIndex = newDisplayIndex;
                do 
                {
                    nextColumn = this.ColumnsInternal.GetColumnAtDisplayIndex(displayIndex);
                    displayIndex++; 
                }
                while (displayIndex < colCount && (nextColumn == null || nextColumn == targetColumn || nextColumn.Visibility == Visibility.Collapsed));
 
                if (nextColumn != null && nextColumn.IsFrozen) 
                {
                    throw DataGridError.DataGrid.CannotMoveNonFrozenColumn(); 
                }
            }
            else 
            {
                // DisplayIndex increases.
                // Throw an exception if the visible frozen column is placed after a non-frozen column 
                // Get the closest visible column placed before the displaced column 
                DataGridColumnBase previousColumn;
                displayIndex = newDisplayIndex; 
                do
                {
                    previousColumn = this.ColumnsInternal.GetColumnAtDisplayIndex(displayIndex); 
                    displayIndex--;
                }
                while (displayIndex >= 0 && (previousColumn == null || previousColumn.Visibility == Visibility.Collapsed)); 
 
                if (previousColumn != null && !previousColumn.IsFrozen)
                { 
                    throw DataGridError.DataGrid.CannotMoveFrozenColumn();
                }
            } 
        }
Example #29
0
 internal void OnColumnWidthChanged(DataGridColumnBase updatedColumn)
 {
     Debug.Assert(updatedColumn != null); 
     if (updatedColumn.Visibility == Visibility.Visible)
     {
         PerformLayout(true /* forceDataCellsHorizontalLayout */); 
     } 
 }
Example #30
0
        //
 


 
        internal void OnColumnCellStyleChanged(DataGridColumnBase column)
        {
            // Set HeaderCell.Style for displayed rows if HeaderCell.Style is not already set 
            for (int childIndex = 0; childIndex < this.DisplayedAndEditedRowCount; childIndex++) 
            {
                DataGridRow row = _cells.Children[childIndex] as DataGridRow; 
                if (row != null)
                {
                    row.Cells[column.Index].Style = column.CellStyle; 
                }
            }
            // Set HeaderCell.Style for prefetched rows if HeaderCell.Style is not already set 
            foreach (DataGridRow row in _prefetchedRows) 
            {
                row.Cells[column.Index].Style = column.CellStyle; 
            }
            // Simply discard the Recyclable rows.  This operation happens less enough that discarding
            // the Recyclable rows here shoudln't be too bad 
            _recyclableRows.Clear();
        }
Example #31
0
        internal void OnInsertedColumn_PreNotification(DataGridColumnBase insertedColumn)
        { 
            // Fix the OldFirstDisplayedScrollingCol 
            this.DisplayData.CorrectColumnIndexAfterInsertion(insertedColumn.Index, 1);
 
            // Fix the Index of all following columns
            CorrectColumnIndexesAfterInsertion(insertedColumn, 1);
 
            Debug.Assert(insertedColumn.Index >= 0);
            Debug.Assert(insertedColumn.Index < this.ColumnsItemsInternal.Count);
            Debug.Assert(insertedColumn.OwningGrid == this); 
 
            if (insertedColumn.DisplayIndex == -1 || insertedColumn.DisplayIndex >= this.ColumnsItemsInternal.Count)
            { 
                // Developer did not assign a DisplayIndex or picked a large number.
                // Choose the Index as the DisplayIndex.
                insertedColumn.DisplayIndexInternal = insertedColumn.Index; 
            }

            CorrectColumnDisplayIndexesAfterInsertion(insertedColumn); 
 
            InsertDisplayedColumnHeader(insertedColumn);
 
            // Insert the missing data cells
            if (_rowCount > 0)
            { 
                int newColumnCount = this.ColumnsItemsInternal.Count;

                if (_cells != null) 
                { 
                    //
                    for (int childIndex = 0; childIndex < this.DisplayedAndEditedRowCount; childIndex++) 
                    {
                        DataGridRow dataGridRow = this._cells.Children[childIndex] as DataGridRow;
                        if (dataGridRow.Cells.Count < newColumnCount) 
                        {
                            AddNewCellPrivate(dataGridRow, insertedColumn);
                        } 
                        foreach (DataGridCell dataGridCell in dataGridRow.Cells) 
                        {
                            if (ColumnRequiresRightGridline(dataGridCell.OwningColumn, true /*includeLastRightGridlineWhenPresent*/)) 
                            {
                                dataGridCell.EnsureGridline();
                            } 
                        }
                    }
                } 
            } 

            // 


 


 
 

 


 


        } 
Example #32
0
 private void CorrectColumnIndexesAfterDeletion(DataGridColumnBase deletedColumn) 
 { 
     Debug.Assert(deletedColumn != null);
     for (int columnIndex = deletedColumn.Index; columnIndex < this.ColumnsItemsInternal.Count; columnIndex++) 
     {
         this.ColumnsItemsInternal[columnIndex].Index = this.ColumnsItemsInternal[columnIndex].Index - 1;
         Debug.Assert(this.ColumnsItemsInternal[columnIndex].Index == columnIndex); 
     }
 }
Example #33
0
        internal void OnRemovedColumn_PreNotification(DataGridColumnBase removedColumn) 
        { 
            Debug.Assert(removedColumn.Index >= 0);
            Debug.Assert(removedColumn.OwningGrid == null); 

            // Intentionally keep the DisplayIndex intact after detaching the column.
            CorrectColumnIndexesAfterDeletion(removedColumn); 

            CorrectColumnDisplayIndexesAfterDeletion(removedColumn);
 
            // Fix the OldFirstDisplayedScrollingCol 
            this.DisplayData.CorrectRowIndexAfterDeletion(removedColumn.Index);
 
            // Fix the existing rows by removing cells at correct index
            int newColumnCount = this.ColumnsItemsInternal.Count;
 
            if (this._cells != null)
            {
                for (int childIndex = 0; childIndex < this.DisplayedAndEditedRowCount; childIndex++) 
                { 
                    DataGridRow dataGridRow = this._cells.Children[childIndex] as DataGridRow;
                    if (dataGridRow.Cells.Count > newColumnCount) 
                    {
                        dataGridRow.Cells.RemoveAt(removedColumn.Index);
                    } 
                }
            }
 
            // 

 


 


 
            RemoveDisplayedColumnHeader(removedColumn); 
        }
Example #34
0
 private void CorrectColumnIndexesAfterInsertion(DataGridColumnBase insertedColumn, int insertionCount) 
 {
     Debug.Assert(insertedColumn != null); 
     Debug.Assert(insertionCount > 0);
     for (int columnIndex = insertedColumn.Index + insertionCount; columnIndex < this.ColumnsItemsInternal.Count; columnIndex++)
     { 
         this.ColumnsItemsInternal[columnIndex].Index = columnIndex;
     }
 } 
Example #35
0
 // Returns the column's width + the potential thickness of the right gridline
 internal double GetEdgedColumnWidth(DataGridColumnBase dataGridColumn) 
 {
     Debug.Assert(dataGridColumn != null);
     return GetEdgedColumnWidth(dataGridColumn, true /*includeLastRightGridlineWhenPresent*/); 
 } 
Example #36
0
        private bool GetColumnEffectiveReadOnlyState(DataGridColumnBase dataGridColumn)
        { 
            Debug.Assert(dataGridColumn != null); 

            return this.IsReadOnly || dataGridColumn.IsReadOnly; 
        }
Example #37
0
 internal double GetEdgedColumnWidth(DataGridColumnBase dataGridColumn, bool includeLastRightGridlineWhenPresent) 
 {
     Debug.Assert(dataGridColumn != null);
     return dataGridColumn.Width + (ColumnRequiresRightGridline(dataGridColumn, includeLastRightGridlineWhenPresent) ? DataGrid.VerticalGridlinesThickness : 0); 
 }
Example #38
0
 private void InsertDisplayedColumnHeader(DataGridColumnBase dataGridColumn)
 { 
     Debug.Assert(dataGridColumn != null);
     if (this.AreColumnHeadersVisible && _columnHeaders != null)
     { 
         dataGridColumn.HeaderCell.Visibility = dataGridColumn.Visibility; 
         Debug.Assert(!this._columnHeaders.Children.Contains(dataGridColumn.HeaderCell));
         _columnHeaders.Children.Insert(dataGridColumn.DisplayIndex, dataGridColumn.HeaderCell); 
     }
 }