private void edit_Click(object sender, RoutedEventArgs e) { if (itemsControl.SelectedItem == null) { MessageBox.Show("No item is selected"); return; } IEditableCollectionView editableCollectionView = itemsControl.Items as IEditableCollectionView; // Create a window that prompts the user to edit an item. ChangeItemWindow win = new ChangeItemWindow(); editableCollectionView.EditItem(itemsControl.SelectedItem); win.DataContext = itemsControl.SelectedItem; // If the user submits the new item, commit the changes. // If the user cancels the edits, discard the changes. if ((bool)win.ShowDialog()) { editableCollectionView.CommitEdit(); } else { editableCollectionView.CancelEdit(); } }
/// <summary> /// Ends the edit transaction and, if possible, restores the original value to the item. /// </summary> void IEditableCollectionView.CancelEdit() { IEditableCollectionView iEditableCollectionView = this.currentView as IEditableCollectionView; if (iEditableCollectionView == null) { throw new InvalidOperationException(ExceptionMessage.Format(ExceptionMessages.MemberNotAllowedForView, "CancelEdit")); } iEditableCollectionView.CancelEdit(); }
/// <summary> /// Executes when the edit mode on the currently selected item /// should be finished and the results of the editing should NOT /// be kept (viewmodel can rollback or implement other fallback methods). /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CancelChanges(object sender, ExecutedRoutedEventArgs e) { IEditableCollectionView ecv = lb.Items as IEditableCollectionView; object selectedItem = lb.SelectedItem; if (selectedItem != null && ecv.IsEditingItem && ecv.CurrentEditItem == selectedItem) { ecv.CancelEdit(); lb.Items.MoveCurrentTo(selectedItem); } }
/// <summary> /// Porzucenie zmian /// </summary> private void OnCancel(object sender, RoutedEventArgs e) { if (m_mode == eDbOperation.Insert) { m_endpoints.CancelNew(); } else { m_endpoints.CancelEdit(); } RestoreTabControl(); }
/// <summary> /// Complete the transaction started by <seealso cref="IEditableCollectionView.EditItem"/>. /// The pending changes (if any) to the item are discarded. /// </summary> void IEditableCollectionView.CancelEdit() { IEditableCollectionView ecv = ProxiedView as IEditableCollectionView; if (ecv != null) { ecv.CancelEdit(); } else { throw new InvalidOperationException(SR.Get(SRID.MemberNotAllowedForView, "CancelEdit")); } }
// Token: 0x06007412 RID: 29714 RVA: 0x00213014 File Offset: 0x00211214 void IEditableCollectionView.CancelEdit() { IEditableCollectionView editableCollectionView = this.ProxiedView as IEditableCollectionView; if (editableCollectionView != null) { editableCollectionView.CancelEdit(); return; } throw new InvalidOperationException(SR.Get("MemberNotAllowedForView", new object[] { "CancelEdit" })); }
private static void RollbackOnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (!(sender is ItemsControl senderItemsControl)) { return; } IEditableCollectionView collection = senderItemsControl.Items as IEditableCollectionView; if (collection.IsEditingItem) { collection.CancelEdit(); } else if (collection.IsAddingNew) { collection.CancelNew(); } }
public void Dispose() { if (!isDisposed) { filterPr.itemsDeferRefreshCount--; if (filterPr.itemsDeferRefreshCount <= 0) { filterPr.itemsDeferRefreshCount = 0; IEditableCollectionView cv = filterPr.CollectionView as IEditableCollectionView; if (cv != null) { if (cv.IsAddingNew) { cv.CancelNew(); } if (cv.IsEditingItem) { cv.CancelEdit(); } } if (filterPr.isFilterActive) { filterPr.CollectionView.Filter = filterPr.filterFunction; } else //if (filterVm.items.PropertyFilter==null) { filterPr.CollectionView.Filter = null; } filterPr.RaiseFiltered(); if (filterPr.itemsDeferRefresh != null) { filterPr.itemsDeferRefresh.Dispose(); } filterPr.itemsDeferRefresh = null; } isDisposed = true; } else { throw new ObjectDisposedException("FilterPresenter(" + filterPr.CollectionView.ToString() + ").GetDeferRefresh()"); } }
private void edit_Click(object sender, RoutedEventArgs e) { if (itemsControl.SelectedItem == null) { MessageBox.Show("No item is selected"); return; } //<SnippetEditItem> IEditableCollectionView editableCollectionView = itemsControl.Items as IEditableCollectionView; // Create a window that prompts the user to edit an item. ChangeItemWindow win = new ChangeItemWindow(); editableCollectionView.EditItem(itemsControl.SelectedItem); win.DataContext = itemsControl.SelectedItem; // If the user submits the new item, commit the changes. // If the user cancels the edits, discard the changes. if ((bool)win.ShowDialog()) { editableCollectionView.CommitEdit(); } else { //<SnippetCancelEdit> // If the objects in the collection can discard pending // changes, calling IEditableCollectionView.CancelEdit // will revert the changes. Otherwise, you must provide // your own logic to revert the changes in the object. if (!editableCollectionView.CanCancelEdit) { // Provide logic to revert changes. } editableCollectionView.CancelEdit(); //</SnippetCancelEdit> } //</SnippetEditItem> }
static void RollbackDataGridOnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { DataGrid senderDatagrid = sender as DataGrid; if (senderDatagrid == null) { return; } IEditableCollectionView collection = senderDatagrid.Items as IEditableCollectionView; if (collection.IsEditingItem) { collection.CancelEdit(); } else if (collection.IsAddingNew) { collection.CancelNew(); } }
/// <summary> /// Cancels the current entity editing and exits the editing mode. /// </summary> /// <param name="dataItem">The entity being edited</param> /// <returns>True if a cancellation operation was invoked.</returns> public bool CancelEdit(object dataItem) { #if FEATURE_IEDITABLECOLLECTIONVIEW IEditableCollectionView editableCollectionView = this.EditableCollectionView; if (editableCollectionView != null) { _owner.NoCurrentCellChangeCount++; this.EndingEdit = true; try { if (editableCollectionView.IsAddingNew && dataItem == editableCollectionView.CurrentAddItem) { editableCollectionView.CancelNew(); return(true); } else if (editableCollectionView.CanCancelEdit) { editableCollectionView.CancelEdit(); return(true); } } finally { _owner.NoCurrentCellChangeCount--; this.EndingEdit = false; } return(false); } #endif IEditableObject editableDataItem = dataItem as IEditableObject; if (editableDataItem != null) { editableDataItem.CancelEdit(); return(true); } return(true); }
public static void Finalize(DataGrid grid) { if (grid == null) { return; } grid.CommitEdit(); // Try to Commit first IEditableCollectionView collection = grid.Items as IEditableCollectionView; if (collection.IsEditingItem) { collection.CancelEdit(); } else if (collection.IsAddingNew) { collection.CancelNew(); //If Save button clicked while editing, the line for new item is disappered. //Hide it temporarily and show it again grid.CanUserAddRows = false; grid.CanUserAddRows = true; } }
/// <summary> /// Cancels the current entity editing and exits the editing mode. /// </summary> /// <param name="dataItem">The entity being edited</param> /// <returns>True if a cancellation operation was invoked.</returns> public bool CancelEdit(object dataItem) { IEditableCollectionView editableCollectionView = EditableCollectionView; if (editableCollectionView != null) { if (editableCollectionView.CanCancelEdit) { editableCollectionView.CancelEdit(); return(true); } return(false); } if (dataItem is IEditableObject editableDataItem) { editableDataItem.CancelEdit(); return(true); } return(true); }
static void RollbackDataGridOnLostFocus(object sender, KeyboardFocusChangedEventArgs e) { DataGrid senderDatagrid = sender as DataGrid; if (senderDatagrid == null) { return; } UIElement focusedElement = Keyboard.FocusedElement as UIElement; if (focusedElement == null) { return; } DataGrid focusedDatagrid = GetParentDatagrid(focusedElement); //let's see if the new focused element is inside a datagrid if (focusedDatagrid == senderDatagrid) { return; //if the new focused element is inside the same datagrid, then we don't need to do anything; //this happens, for instance, when we enter in edit-mode: the DataGrid element loses keyboard-focus, which passes to the selected DataGridCell child } //otherwise, the focus went outside the datagrid; in order to avoid exceptions like ("DeferRefresh' is not allowed during an AddNew or EditItem transaction") //or ("CommitNew is not allowed for this view"), we undo the possible pending changes, if any IEditableCollectionView collection = senderDatagrid.Items as IEditableCollectionView; if (collection.IsEditingItem) { collection.CancelEdit(); } else if (collection.IsAddingNew) { collection.CancelNew(); } }
public void CancelEdit() { _collectionView.CancelEdit(); }