private bool EndRowEdit(bool commitRowEdit, bool exitEditingMode) { if (this._editingRow == null) { return true; } DataGridDataErrorEventArgs dataError = null; if (commitRowEdit) { dataError = CommitRowEdit(exitEditingMode); if (dataError != null) { if (dataError.ThrowException) { throw dataError.Exception; } if (dataError.Cancel) { return false; } } } if (!commitRowEdit || dataError != null) { dataError = CancelRowEdit(exitEditingMode); if (null != dataError) { if (dataError.ThrowException) { throw dataError.Exception; } if (dataError.Cancel) { return false; } } } if (exitEditingMode) { DataGridRow editingRow = this._editingRow; if (this._editingRowLocation == DataGridEditingRowLocation.Top || this._editingRowLocation == DataGridEditingRowLocation.Bottom) { RemoveRow(this._editingRow, this._editingRowLocation == DataGridEditingRowLocation.Top ? 0 : this._lastDisplayedRowIndex - this._firstDisplayedRowIndex + 1); this._editingRow = null; this._editingRowLocation = DataGridEditingRowLocation.Inline; } else { if (this.AreRowHeadersVisible) { this._editingRow = null; editingRow.HeaderCell.ApplyRowStatus(true /*animate*/); } else { this._editingRow = null; } editingRow.ApplyBackgroundBrush(true /*animate*/); } } return true; }
/// <summary> /// Exits editing mode without trying to commit or revert the editing, and /// without repopulating the edited row's cell. /// </summary> private void ExitEdit(bool keepFocus) { if (this._editingColumnIndex == -1) { return; } Debug.Assert(this._editingRow != null); Debug.Assert(this._editingColumnIndex >= 0); Debug.Assert(this._editingColumnIndex < this.ColumnsItemsInternal.Count); Debug.Assert(this._editingColumnIndex == this.CurrentColumnIndex); Debug.Assert(this.EditingRowIndex == this.CurrentRowIndex); this._editingColumnIndex = -1; this._editingRow.Cells[this.CurrentColumnIndex].ApplyCellState(false /*animate*/); // this.IsTabStop = true; DataGridRow editingRow = this._editingRow; if (this._editingRowLocation == DataGridEditingRowLocation.Top || this._editingRowLocation == DataGridEditingRowLocation.Bottom) { RemoveRow(this._editingRow, this._editingRowLocation == DataGridEditingRowLocation.Top ? 0 : this._lastDisplayedRowIndex - this._firstDisplayedRowIndex + 1); this._editingRow = null; this._editingRowLocation = DataGridEditingRowLocation.Inline; } else { if (this.AreRowHeadersVisible) { this._editingRow = null; editingRow.HeaderCell.ApplyRowStatus(true /*animate*/); } else { this._editingRow = null; } editingRow.ApplyBackgroundBrush(true /*animate*/); } if (keepFocus) { bool success = Focus(); Debug.Assert(success); } }
public DataGrid() { this.TabNavigation = KeyboardNavigationMode.Once; this.IsTabStop = true; this.KeyDown += new KeyEventHandler(DataGrid_KeyDown); this.KeyUp += new KeyEventHandler(DataGrid_KeyUp); this.GotFocus += new RoutedEventHandler(DataGrid_GotFocus); this.LostFocus += new RoutedEventHandler(DataGrid_LostFocus); this.SetValueNoCallback(GridlinesVisibilityProperty, DataGridGridlines.All); this._prefetchedRows = new List<DataGridRow>(); this._preparedRows = new List<DataGridRow>(); this._recyclableRows = new List<DataGridRow>(); this._editingBoundCells = new List<DataGridCell>(2); this.SelectedItemsInternal = new DataGridSelectedItemsCollection(this); this.ColumnsInternal = CreateColumnsInstance(); this.SetValueNoCallback(ColumnWidthProperty, DATAGRID_defaultColumnWidth); this.DisplayData = new DataGridDisplayData(); this.SetValueNoCallback(RowHeightProperty, DATAGRID_defaultRowHeight); this._minColumnWidth = DATAGRID_defaultMinColumnWidth; this._minRowHeight = DataGridRow.DATAGRIDROW_minMinHeight; this.DataConnection = new DataGridDataConnection(this); this._editingRowLocation = DataGridEditingRowLocation.Inline; this._newRowLocation = DataGridNewRowLocation.Inline; this._showDetailsTable = new IndexToValueTable<Visibility>(); this.SetValueNoCallback(RowDetailsVisibilityProperty, DATAGRID_defaultRowDetailsVisibility); this.AnchorRowIndex = -1; this._editingColumnIndex = -1; this._mouseOverRowIndex = null; this.CurrentCellCoordinates = new DataGridCellCoordinates(-1, -1); this.SetValueNoCallback(HeadersVisibilityProperty, DATAGRID_defaultHeadersVisibility); this.SetValueNoCallback(HorizontalScrollBarVisibilityProperty, DATAGRID_defaultHorizontalScrollBarVisibility); this.SetValueNoCallback(VerticalScrollBarVisibilityProperty, DATAGRID_defaultVerticalScrollBarVisibility); this.SetValueNoCallback(ColumnHeadersHeightProperty, DATAGRID_defaultColumnHeadersHeight); this.SetValueNoCallback(RowHeadersWidthProperty, DATAGRID_defaultRowHeadersWidth); this.SetValueNoCallback(SelectionModeProperty, DATAGRID_defaultSelectionMode); // this.CanUserResizeColumns = DATAGRID_defaultCanUserResizeColumns; }