/// <summary> /// Instantiates a new instance of this class. /// </summary> /// <param name="column">The column of the cell that is about to exit edit mode.</param> /// <param name="row">The row container of the cell container that is about to exit edit mode.</param> /// <param name="editingElement">The editing element within the cell.</param> /// <param name="editingUnit">The editing unit that is about to leave edit mode.</param> public DataGridCellEditEndingEventArgs(DataGridColumn column, DataGridRow row, FrameworkElement editingElement, DataGridEditAction editAction) { _dataGridColumn = column; _dataGridRow = row; _editingElement = editingElement; _editAction = editAction; }
/// <summary> /// Instantiates a new instance of this class. /// </summary> /// <param name="column">The column of the cell that is about to exit edit mode.</param> /// <param name="row">The row container of the cell container that is about to exit edit mode.</param> /// <param name="editingElement">The editing element within the cell.</param> /// <param name="editAction">The editing action that will be taken.</param> public DataGridCellEditEndingEventArgs(DataGridColumn column, DataGridRow row, Control editingElement, DataGridEditAction editAction) { Column = column; Row = row; EditingElement = editingElement; EditAction = editAction; }
private void EnqueueRowEditEndingEvent(DataGridEditAction editAction, bool cancelEvent) { EditFirstCell( DataGridEditAction.Commit /*cellEditAction*/, editAction /*rowEditAction*/, new DataGridDelegate( delegate(DataGrid dataGrid) { this._cancelCellEvent = false; this._cancelRowEvent = cancelEvent; this._rowEditEndingEventArgs = null; this._eventCount = 0; dataGrid.RowEditEnding -= new EventHandler <DataGridRowEditEndingEventArgs>(dataGrid_RowEditEnding); dataGrid.RowEditEnding += new EventHandler <DataGridRowEditEndingEventArgs>(dataGrid_RowEditEnding); this._currentCellChangedCount = 0; dataGrid.CurrentCellChanged -= new EventHandler <EventArgs>(dataGrid_CurrentCellChanged); dataGrid.CurrentCellChanged += new EventHandler <EventArgs>(dataGrid_CurrentCellChanged); this._selectionChangedCount = 0; dataGrid.SelectionChanged -= new SelectionChangedEventHandler(dataGrid_SelectionChanged); dataGrid.SelectionChanged += new SelectionChangedEventHandler(dataGrid_SelectionChanged); }), new DataGridCellValidateDelegate( delegate(DataGrid dataGrid, object beforeValue, object afterValue) { if (cancelEvent) { Assert.IsNotNull(dataGrid.EditingRow); } else { Assert.IsNull(dataGrid.EditingRow); } // Ensure that the RowEditEndingEvents were raised Assert.IsNotNull(this._rowEditEndingEventArgs, "RowEditEnding wasn't raised"); Assert.AreEqual(1, this._eventCount, "Event was raised too many times"); Assert.AreEqual(1, this._currentCellChangedCount, "Event was raised too many times"); Assert.AreEqual(1, this._selectionChangedCount, "Event was raised too many times"); Assert.AreEqual(editAction, this._rowEditEndingEventArgs.EditAction, "Incorrect RowEditEnding EditAction"); Assert.AreEqual(dataGridRow.Index, this._rowEditEndingEventArgs.Row.Index, "Incorrect RowEditEnding Row"); }), new DataGridDelegate( delegate(DataGrid dataGrid) { dataGrid.RowEditEnding -= new EventHandler <DataGridRowEditEndingEventArgs>(dataGrid_RowEditEnding); dataGrid.CurrentCellChanged -= new EventHandler <EventArgs>(dataGrid_CurrentCellChanged); dataGrid.SelectionChanged -= new SelectionChangedEventHandler(dataGrid_SelectionChanged); })); }
private void EnqueueCellEditEndingEvent(DataGridEditAction editAction, bool cancelEvent) { EditFirstCell( editAction /*cellEditAction*/, null /*rowEditAction*/, new DataGridDelegate( delegate(DataGrid dataGrid) { this._cancelCellEvent = cancelEvent; this._cancelRowEvent = false; this._cellEditEndingEventArgs = null; this._eventCount = 0; dataGrid.CellEditEnding -= new EventHandler <DataGridCellEditEndingEventArgs>(dataGrid_CellEditEnding); dataGrid.CellEditEnding += new EventHandler <DataGridCellEditEndingEventArgs>(dataGrid_CellEditEnding); this._currentCellChangedCount = 0; dataGrid.CurrentCellChanged += new EventHandler <EventArgs>(dataGrid_CurrentCellChanged); this._selectionChangedCount = 0; dataGrid.SelectionChanged += new SelectionChangedEventHandler(dataGrid_SelectionChanged); }), new DataGridCellValidateDelegate( delegate(DataGrid dataGrid, object beforeValue, object afterValue) { // Ensure that the CellEditEndingEvent was raised Assert.IsNotNull(this._cellEditEndingEventArgs, "CellEditEnding wasn't raised"); Assert.AreEqual(1, this._eventCount, "Event was raised too many times"); Assert.AreEqual(1, this._currentCellChangedCount, "Event was raised too many times"); Assert.AreEqual(1, this._selectionChangedCount, "Event was raised too many times"); Assert.AreEqual(0, this._cellEditEndingEventArgs.Column.Index, "Incorrect CellEditEnding Column"); Assert.AreEqual(editAction, this._cellEditEndingEventArgs.EditAction, "Incorrect CellEditEnding EditAction"); Assert.AreEqual(0, this._cellEditEndingEventArgs.Row.Index, "Incorrect CellEditEnding Row"); if (editAction == DataGridEditAction.Commit && !cancelEvent) { Assert.AreNotEqual(beforeValue, afterValue, "New value was not committed"); } else { Assert.AreEqual(beforeValue, afterValue, "New value was committed"); } }), new DataGridDelegate( delegate(DataGrid dataGrid) { dataGrid.CellEditEnding -= new EventHandler <DataGridCellEditEndingEventArgs>(dataGrid_CellEditEnding); dataGrid.CurrentCellChanged -= new EventHandler <EventArgs>(dataGrid_CurrentCellChanged); dataGrid.SelectionChanged -= new SelectionChangedEventHandler(dataGrid_SelectionChanged); })); }
/// <summary> /// Instantiates a new instance of this class. /// </summary> /// <param name="column">The column of the cell that has just exited edit mode.</param> /// <param name="row">The row container of the cell container that has just exited edit mode.</param> /// <param name="editAction">The editing action that has been taken.</param> public DataGridCellEditEndedEventArgs(DataGridColumn column, DataGridRow row, DataGridEditAction editAction) { Column = column; Row = row; EditAction = editAction; }
// // Summary: // Instantiates a new instance of the System.Windows.Controls.DataGridRowEditEndedEventArgs // class. // // Parameters: // row: // The row that has just exited edit mode. // // editAction: // The System.Windows.Controls.DataGridEditAction that indicates whether the edit // was committed or canceled. public DataGridRowEditEndedEventArgs(DataGridRow row, DataGridEditAction editAction) { }
private bool EndRowEdit(DataGridEditAction editAction, bool exitEditingMode, bool raiseEvents) { if (this.EditingRow == null || this.DataConnection.CommittingEdit) { return true; } if (this._editingColumnIndex != -1 || (editAction == DataGridEditAction.Cancel && raiseEvents && !((this.DataConnection.EditableCollectionView != null && this.DataConnection.EditableCollectionView.CanCancelEdit) || (this.EditingRow.DataContext is IEditableObject)))) { // Ending the row edit will fail immediately under the following conditions: // 1. We haven't ended the cell edit yet. // 2. We're trying to cancel edit when the underlying DataType is not an IEditableObject, // because we have no way to properly restore the old value. We will only allow this to occur // if raiseEvents == false, which means we're internally forcing a cancel. return false; } DataGridRow editingRow = this.EditingRow; if (raiseEvents) { DataGridRowEditEndingEventArgs e = new DataGridRowEditEndingEventArgs(this.EditingRow, editAction); OnRowEditEnding(e); if (e.Cancel) { // RowEditEnding has been cancelled return false; } // Editing states might have been changed in the RowEditEnding handlers if (this._editingColumnIndex != -1) { return false; } if (editingRow != this.EditingRow) { return true; } } // Call the appropriate commit or cancel methods if (editAction == DataGridEditAction.Commit) { if (!CommitRowEdit(exitEditingMode)) { return false; } } else { if (!CancelRowEdit(exitEditingMode) && raiseEvents) { // We failed to cancel edit so we should abort unless we're forcing a cancel return false; } } ResetValidationStatus(); // Update the previously edited row's state if (exitEditingMode && editingRow == this.EditingRow) { // Unwire the INDEI event handlers foreach (INotifyDataErrorInfo indei in this._validationItems.Keys) { indei.ErrorsChanged -= new EventHandler<DataErrorsChangedEventArgs>(ValidationItem_ErrorsChanged); } this._validationItems.Clear(); this.RemoveEditingElements(); ResetEditingRow(); } // Raise the RowEditEnded event if (raiseEvents) { OnRowEditEnded(new DataGridRowEditEndedEventArgs(editingRow, editAction)); } return true; }
public DataGridCellEditEndingEventArgs(DataGridColumn column, DataGridRow row, FrameworkElement editingElement, DataGridEditAction editAction) { }
public DataGridRowEditEndingEventArgs(DataGridRow row, DataGridEditAction editAction) { }
/// <summary> /// Instantiates a new instance of this class. /// </summary> /// <param name="column">The column of the cell that has just exited edit mode.</param> /// <param name="row">The row container of the cell container that has just exited edit mode.</param> /// <param name="editAction">The editing action that has been taken.</param> public DataGridCellEditEndedEventArgs(DataGridColumn column, DataGridRow row, DataGridEditAction editAction) { this.Column = column; this.Row = row; this.EditAction = editAction; }
private bool EndCellEdit(DataGridEditAction editAction, bool exitEditingMode, bool keepFocus, bool raiseEvents) { if (this._editingColumnIndex == -1) { return true; } 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.EditingRow != null && this.EditingRow.Slot == this.CurrentSlot); // Cache these to see if they change later int currentSlot = this.CurrentSlot; int currentColumnIndex = this.CurrentColumnIndex; // We're ready to start ending, so raise the event DataGridCell editingCell = this.EditingRow.Cells[this._editingColumnIndex]; FrameworkElement editingElement = editingCell.Content as FrameworkElement; if (editingElement == null) { return false; } if (raiseEvents) { DataGridCellEditEndingEventArgs e = new DataGridCellEditEndingEventArgs(this.CurrentColumn, this.EditingRow, editingElement, editAction); OnCellEditEnding(e); if (e.Cancel) { // CellEditEnding has been cancelled return false; } // Ensure that the current cell wasn't changed in the user's CellEditEnding handler if (this._editingColumnIndex == -1 || currentSlot != this.CurrentSlot || currentColumnIndex != this.CurrentColumnIndex) { return true; } Debug.Assert(this.EditingRow != null); Debug.Assert(this.EditingRow.Slot == currentSlot); Debug.Assert(this._editingColumnIndex != -1); Debug.Assert(this._editingColumnIndex == this.CurrentColumnIndex); } // If we're canceling, let the editing column repopulate its old value if it wants if (editAction == DataGridEditAction.Cancel) { this.CurrentColumn.CancelCellEditInternal(editingElement, this._uneditedValue); // Ensure that the current cell wasn't changed in the user column's CancelCellEdit if (this._editingColumnIndex == -1 || currentSlot != this.CurrentSlot || currentColumnIndex != this.CurrentColumnIndex) { return true; } Debug.Assert(this.EditingRow != null); Debug.Assert(this.EditingRow.Slot == currentSlot); Debug.Assert(this._editingColumnIndex != -1); Debug.Assert(this._editingColumnIndex == this.CurrentColumnIndex); } // If we're committing, explicitly update the source but watch out for any validation errors if (editAction == DataGridEditAction.Commit) { foreach (BindingInfo bindingData in this.CurrentColumn.GetInputBindings(editingElement, this.CurrentItem)) { bindingData.Element.BindingValidationError += new EventHandler<ValidationErrorEventArgs>(EditingElement_BindingValidationError); bindingData.BindingExpression.UpdateSource(); } if (this._bindingValidationError) { ScrollSlotIntoView(this.CurrentColumnIndex, this.CurrentSlot, false /*forCurrentCellChange*/, true /*forceHorizontalScroll*/); this._bindingValidationError = false; // Default the row and DataGrid IsValid to false if the cell is invalid editingCell.IsValid = false; editingCell.ApplyCellState(true); this.EditingRow.IsValid = false; this.EditingRow.ApplyState(true); this.IsValid = false; return false; } } // Either the user has canceled edit or the commmit was successful, so the edited cell should // be marked as valid -- unless it is related to the currently selected entity-level error. editingCell.IsValid = true; if (this._selectedValidationSummaryItem != null) { foreach (ValidationSummaryItemSource source in this._selectedValidationSummaryItem.Sources) { if (source.Control == editingCell) { editingCell.IsValid = false; } } } editingCell.ApplyCellState(true); // Revalidate the row if there are any entity-level errors associated with the cell // that just ended edit or not associated with any specific cell at all if (!this.EditingRow.IsValid) { if (this._validationResults.Count > 0) { foreach (ValidationResult validationResult in this._validationResults) { bool revalidate = false; foreach (string memberName in validationResult.MemberNames) { Debug.Assert(this.DataConnection.DataType != null); if (memberName == this.DataConnection.DataType.Name || this.ColumnsItemsInternal[this.EditingColumnIndex].BindingPaths.Contains(memberName)) { revalidate = true; break; } } if (revalidate) { ValidateEditingRow(); break; } } } else { this.IsValid = true; this.EditingRow.IsValid = true; this.EditingRow.ApplyState(true); } } // Detach from any remaining BindingValidationError events // note: We do this outside of the Commit scope in case CancelEdit was called within the handler foreach (BindingInfo bindingData in this.CurrentColumn.GetInputBindings(editingElement, this.CurrentItem)) { bindingData.Element.BindingValidationError -= new EventHandler<ValidationErrorEventArgs>(EditingElement_BindingValidationError); } if (exitEditingMode) { this._editingColumnIndex = -1; editingCell.ApplyCellState(true /*animate*/); // this.IsTabStop = true; if (keepFocus && editingElement.ContainsFocusedElement()) { this.Focus(); } PopulateCellContent(!exitEditingMode /*isCellEdited*/, this.CurrentColumn, this.EditingRow, editingCell); } // We're done, so raise the CellEditEnded event if (raiseEvents) { OnCellEditEnded(new DataGridCellEditEndedEventArgs(this.CurrentColumn, this.EditingRow, editAction)); } // There's a chance that somebody reopened this cell for edit within the CellEditEnded handler, // so we should return false if we were supposed to exit editing mode, but we didn't return !(exitEditingMode && currentColumnIndex == this._editingColumnIndex); }
/// <summary> /// Instantiates a new instance of this class. /// </summary> /// <param name="row">The row container of the cell container that is about to exit edit mode.</param> /// <param name="editingUnit">The editing unit that is about to leave edit mode.</param> public DataGridRowEditEndingEventArgs(DataGridRow row, DataGridEditAction editAction) { _dataGridRow = row; _editAction = editAction; }
public DataGridCellEditEndingEventArgs(DataGridColumn column, DataGridRow row, System.Windows.FrameworkElement editingElement, DataGridEditAction editAction) { }
public virtual void EditFirstCell(DataGridEditAction cellEditAction, DataGridEditAction?rowEditAction, DataGridDelegate subscribeToEvent, DataGridCellValidateDelegate validateEvent, DataGridDelegate unsubscribeToEvent) { // The first customer property should always be a string if (properties[0].PropertyType == typeof(string)) { DataGrid dataGrid = new DataGrid(); string originalValue; string updatedValue; dataGrid.ItemsSource = null; dataGrid.SelectedItems.Clear(); rowLoaded = false; dataGridRow = null; isLoaded = false; dataGrid.Loaded += new RoutedEventHandler(dataGrid_Loaded); dataGrid.ColumnWidth = new DataGridLength(50); dataGrid.Width = 650; dataGrid.Height = 250; CustomerList customerList = new CustomerList(1); customerList[0].LastName = "A"; PagedCollectionView pagedCollectionView = new PagedCollectionView(customerList); pagedCollectionView.SortDescriptions.Add(new System.ComponentModel.SortDescription("LastName", System.ComponentModel.ListSortDirection.Ascending)); TestPanel.Children.Add(dataGrid); EnqueueConditional(delegate { return(isLoaded); }); this.EnqueueYieldThread(); EnqueueCallback(delegate { dataGrid.LoadingRow += new EventHandler <DataGridRowEventArgs>(dataGrid_LoadingRowGetRow); subscribeToEvent(dataGrid); dataGrid.ItemsSource = pagedCollectionView; }); EnqueueConditional(delegate { return(rowLoaded); }); this.EnqueueYieldThread(); EnqueueCallback(delegate { dataGrid.LoadingRow -= new EventHandler <DataGridRowEventArgs>(dataGrid_LoadingRowGetRow); bool success = dataGrid.BeginEdit(); Assert.IsTrue(success, "BeginEdit was not successful"); }); this.EnqueueYieldThread(); //} EnqueueCallback(delegate { //Set column to valid value Assert.IsTrue(dataGrid.Columns[0].GetCellContent(customerList[0]) is TextBox, "Not a TextBox"); TextBox cell = ((TextBox)dataGrid.CurrentColumn.GetCellContent(customerList[0])); originalValue = cell.Text; ((TextBox)dataGrid.CurrentColumn.GetCellContent(customerList[0])).Text = Common.RandomString(10); updatedValue = cell.Text; // Either commit or cancel the cell edit if (cellEditAction == DataGridEditAction.Commit) { dataGrid.CommitEdit(DataGridEditingUnit.Cell, true /*exitEditing*/); } else { dataGrid.CancelEdit(DataGridEditingUnit.Cell); } // Either commit or cancel the row edit if (rowEditAction == DataGridEditAction.Commit) { dataGrid.CommitEdit(DataGridEditingUnit.Row, true /*exitEditing*/); } else if (rowEditAction == DataGridEditAction.Cancel) { dataGrid.CancelEdit(DataGridEditingUnit.Row); } updatedValue = properties[0].GetValue(customerList[0], null) as String; validateEvent(dataGrid, originalValue, updatedValue); unsubscribeToEvent(dataGrid); }); } }
/// <summary> /// Instantiates a new instance of this class. /// </summary> /// <param name="row">The row container of the cell container that has just exited edit mode.</param> /// <param name="editAction">The editing action that has been taken.</param> public DataGridRowEditEndedEventArgs(DataGridRow row, DataGridEditAction editAction) { this.Row = row; this.EditAction = editAction; }
/// <summary> /// Instantiates a new instance of this class. /// </summary> /// <param name="row">The row container of the cell container that is about to exit edit mode.</param> /// <param name="editAction">The editing action that will be taken.</param> public DataGridRowEditEndingEventArgs(DataGridRow row, DataGridEditAction editAction) { this.Row = row; this.EditAction = editAction; }
private bool EndCellEdit(DataGridEditAction editAction, bool exitEditingMode, bool keepFocus, bool raiseEvents) { if (this._editingColumnIndex == -1) { return true; } 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.EditingRow != null && this.EditingRow.Slot == this.CurrentSlot); // Cache these to see if they change later int currentSlot = this.CurrentSlot; int currentColumnIndex = this.CurrentColumnIndex; // We're ready to start ending, so raise the event DataGridCell editingCell = this.EditingRow.Cells[this._editingColumnIndex]; FrameworkElement editingElement = editingCell.Content as FrameworkElement; if (editingElement == null) { return false; } if (raiseEvents) { DataGridCellEditEndingEventArgs e = new DataGridCellEditEndingEventArgs(this.CurrentColumn, this.EditingRow, editingElement, editAction); OnCellEditEnding(e); if (e.Cancel) { // CellEditEnding has been cancelled return false; } // Ensure that the current cell wasn't changed in the user's CellEditEnding handler if (this._editingColumnIndex == -1 || currentSlot != this.CurrentSlot || currentColumnIndex != this.CurrentColumnIndex) { return true; } Debug.Assert(this.EditingRow != null); Debug.Assert(this.EditingRow.Slot == currentSlot); Debug.Assert(this._editingColumnIndex != -1); Debug.Assert(this._editingColumnIndex == this.CurrentColumnIndex); } this._bindingValidationResults.Clear(); // If we're canceling, let the editing column repopulate its old value if it wants if (editAction == DataGridEditAction.Cancel) { this.CurrentColumn.CancelCellEditInternal(editingElement, this._uneditedValue); // Ensure that the current cell wasn't changed in the user column's CancelCellEdit if (this._editingColumnIndex == -1 || currentSlot != this.CurrentSlot || currentColumnIndex != this.CurrentColumnIndex) { return true; } Debug.Assert(this.EditingRow != null); Debug.Assert(this.EditingRow.Slot == currentSlot); Debug.Assert(this._editingColumnIndex != -1); Debug.Assert(this._editingColumnIndex == this.CurrentColumnIndex); // Re-validate this.ValidateEditingRow(true /*scrollIntoView*/, false /*wireEvents*/); } // If we're committing, explicitly update the source but watch out for any validation errors if (editAction == DataGridEditAction.Commit) { foreach (BindingInfo bindingData in this.CurrentColumn.GetInputBindings(editingElement, this.CurrentItem)) { Debug.Assert(bindingData.BindingExpression.ParentBinding != null); this._updateSourcePath = bindingData.BindingExpression.ParentBinding.Path != null ? bindingData.BindingExpression.ParentBinding.Path.Path : null; bindingData.Element.BindingValidationError += new EventHandler<ValidationErrorEventArgs>(EditingElement_BindingValidationError); bindingData.BindingExpression.UpdateSource(); bindingData.Element.BindingValidationError -= new EventHandler<ValidationErrorEventArgs>(EditingElement_BindingValidationError); } // Re-validate this.ValidateEditingRow(true /*scrollIntoView*/, false /*wireEvents*/); if (this._bindingValidationResults.Count > 0) { ScrollSlotIntoView(this.CurrentColumnIndex, this.CurrentSlot, false /*forCurrentCellChange*/, true /*forceHorizontalScroll*/); return false; } } if (exitEditingMode) { this._editingColumnIndex = -1; editingCell.ApplyCellState(true /*animate*/); // this.IsTabStop = true; if (keepFocus && editingElement.ContainsFocusedElement()) { this.Focus(); } PopulateCellContent(!exitEditingMode /*isCellEdited*/, this.CurrentColumn, this.EditingRow, editingCell); } // We're done, so raise the CellEditEnded event if (raiseEvents) { OnCellEditEnded(new DataGridCellEditEndedEventArgs(this.CurrentColumn, this.EditingRow, editAction)); } // There's a chance that somebody reopened this cell for edit within the CellEditEnded handler, // so we should return false if we were supposed to exit editing mode, but we didn't return !(exitEditingMode && currentColumnIndex == this._editingColumnIndex); }
// // Summary: // Instantiates a new instance of the System.Windows.Controls.DataGridCellEditEndedEventArgs // class. // // Parameters: // column: // The column that contains the cell that has just exited edit mode. // // row: // The row that contains the cell that has just exited edit mode. // // editAction: // The System.Windows.Controls.DataGridEditAction that indicates whether the edit // was committed or canceled. public DataGridCellEditEndedEventArgs(DataGridColumn column, DataGridRow row, DataGridEditAction editAction) { }