private void CommitEdit(ICollectionView view) { if (view is IEditableCollectionView) { IEditableCollectionView editableView = view as IEditableCollectionView; if (editableView.IsAddingNew || editableView.IsEditingItem) { editableView.CommitEdit(); editableView.CommitEdit(); } } }
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(); } }
static void CommitDataGridOnLostFocus(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; try { collection.CommitEdit(); } catch { } }
/// <summary> /// Commits the current entity editing and exits the editing mode. /// </summary> /// <param name="dataItem">The entity being edited</param> /// <returns>True if a commit operation was invoked.</returns> public bool EndEdit(object dataItem) { IEditableCollectionView editableCollectionView = this.EditableCollectionView; if (editableCollectionView != null) { // IEditableCollectionView.CommitEdit can potentially change currency. If it does, // we don't want to attempt a second commit inside our CurrentChanging event handler. this._owner.NoCurrentCellChangeCount++; this.CommittingEdit = true; try { editableCollectionView.CommitEdit(); } finally { this._owner.NoCurrentCellChangeCount--; this.CommittingEdit = false; } return(true); } IEditableObject editableDataItem = dataItem as IEditableObject; if (editableDataItem != null) { editableDataItem.EndEdit(); } return(true); }
/// <summary> /// Changes the name of a city on an item. /// </summary> /// <param name="sender">The Object that originated the event.</param> /// <param name="e">The event arguments.</param> void OnChangeCityClick(Object sender, RoutedEventArgs e) { IEditableCollectionView iEditableCollectionView = this.ListView.Items as IEditableCollectionView; iEditableCollectionView.EditItem(this.consumerCollection[3]); this.consumerCollection[3].City = "Aberdene"; iEditableCollectionView.CommitEdit(); }
/// <summary> /// Ends the edit transaction and saves the pending changes. /// </summary> void IEditableCollectionView.CommitEdit() { IEditableCollectionView iEditableCollectionView = this.currentView as IEditableCollectionView; if (iEditableCollectionView == null) { throw new InvalidOperationException(ExceptionMessage.Format(ExceptionMessages.MemberNotAllowedForView, "CommitEdit")); } iEditableCollectionView.CommitEdit(); }
/// <summary> /// Executes when the edit mode on the currently selected item /// should be finished and the results of the editing should be kept. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CommitChanges(object sender, ExecutedRoutedEventArgs e) { IEditableCollectionView ecv = lb.Items as IEditableCollectionView; object selectedItem = lb.Items.CurrentItem; if (selectedItem != null && ecv.IsEditingItem && ecv.CurrentEditItem == selectedItem) { ecv.CommitEdit(); lb.Items.MoveCurrentTo(selectedItem); } }
private void CheckDataGrid(DataGrid grid) { IEditableCollectionView collection = grid.Items; if (collection.IsEditingItem) { collection.CommitEdit(); } if (collection.IsAddingNew) { collection.CommitNew(); } }
/// <summary> /// Complete the transaction started by <seealso cref="IEditableCollectionView.EditItem"/>. /// The pending changes (if any) to the item are committed. /// </summary> void IEditableCollectionView.CommitEdit() { IEditableCollectionView ecv = ProxiedView as IEditableCollectionView; if (ecv != null) { ecv.CommitEdit(); } else { throw new InvalidOperationException(SR.Get(SRID.MemberNotAllowedForView, "CommitEdit")); } }
// Token: 0x06007411 RID: 29713 RVA: 0x00212FD4 File Offset: 0x002111D4 void IEditableCollectionView.CommitEdit() { IEditableCollectionView editableCollectionView = this.ProxiedView as IEditableCollectionView; if (editableCollectionView != null) { editableCollectionView.CommitEdit(); return; } throw new InvalidOperationException(SR.Get("MemberNotAllowedForView", new object[] { "CommitEdit" })); }
public void NonEditableEntitySetDoesNotThrowFromCommitEdit() { DomainDataSourceView dataView = GetConfigurableView(EntitySetOperations.Add | EntitySetOperations.Remove); City newCity = new City { Name = "City", StateName = "ST" }; dataView.Add(newCity); IEditableCollectionView iecv = ((IEditableCollectionView)dataView); iecv.EditItem(newCity); // Test is to ensure that no exception is thrown from calling CommitEdit iecv.CommitEdit(); }
static void CommitDataGridOnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { DataGrid senderDatagrid = sender as DataGrid; if (senderDatagrid == null) { return; } IEditableCollectionView collection = senderDatagrid.Items as IEditableCollectionView; try { collection.CommitEdit(); } catch { } }
/// <summary> /// Zatwierdzenie zmian /// </summary> private void OnCommit(object sender, RoutedEventArgs e) { string errmsg = string.Empty; if (m_mode == eDbOperation.Insert) { var schedule = m_schedules.CurrentAddItem as FtpSchedule; if (!ValidateSchedule(schedule)) { return; } schedule.Endpoint = m_mainWnd.m_tbHarmonogramy.m_selectedEndpoint.XX; errmsg = FtpDiligentDatabaseClient.ModifySchedule(schedule.GetModel(), m_mode); if (string.IsNullOrEmpty(errmsg)) { schedule.XX = IFtpDiligentDatabaseClient.m_lastInsertedKey; m_schedules.CommitNew(); } } else { var schedule = m_schedules.CurrentEditItem as FtpSchedule; if (!ValidateSchedule(schedule)) { return; } errmsg = FtpDiligentDatabaseClient.ModifySchedule(schedule.GetModel(), m_mode); if (string.IsNullOrEmpty(errmsg)) { m_schedules.CommitEdit(); } } if (string.IsNullOrEmpty(errmsg)) { RestoreTabControl(); } else { m_mainWnd.ShowErrorInfo(eSeverityCode.Error, errmsg); } }
//удалить строку private void deletestring_Click(object sender, RoutedEventArgs e) { IEditableCollectionView iecv = CollectionViewSource.GetDefaultView(DataGrid1.ItemsSource) as IEditableCollectionView; while (DataGrid1.SelectedIndex >= 0) { int selectedIndex = DataGrid1.SelectedIndex; DataGridRow dgr = DataGrid1.ItemContainerGenerator.ContainerFromIndex(selectedIndex) as DataGridRow; dgr.IsSelected = false; if (iecv.IsEditingItem) { iecv.CommitEdit(); iecv.RemoveAt(selectedIndex); } else { iecv.RemoveAt(selectedIndex); } } #region //DataRowView rowView = DataGrid1.SelectedItems[0] as DataRowView; // DataRowView row = (DataRowView)DataGrid1.SelectedCells.; //ObservableCollection<DataRow> data = (ObservableCollection<DataRow>)DataGrid1.ItemsSource; //data.Remove(row); //DataGrid1.Items.Remove(selectedRow); // List.Remove(SelectedDataGrid1Item); // DataSet1.OurTableRow GetSelectedRow() // { // String SelectedPraktikaID = DataGrid1.CurrentRow.Cells["PropId"].value.toString; // DataSet1.OurTableRow SelectedRow = //OurTableDataTable.FindByPropID(SelectedPraktikaID); // return SelectedRow; // } // GetSelectedRow().Delete(); }
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> }
private void CollectionView_PagingTestCurrentChanging(object source, CurrentChangingEventArgs e) { if (this._cancelCurrencyMove == true) { e.Cancel = true; } else if (this._cancelCurrencyMove == false) { // Commit the edited/addition item before the page move occurs. IEditableCollectionView editableCollectionView = (IEditableCollectionView)source; if (editableCollectionView.IsAddingNew) { editableCollectionView.CommitNew(); } else { editableCollectionView.CommitEdit(); } } }
internal DisposeItemsDeferRefresh(FilterPresenter filterVm) { this.filterPr = filterVm; IEditableCollectionView cv = filterPr.CollectionView as IEditableCollectionView; if (cv != null) { if (cv.IsAddingNew) { cv.CommitNew(); } if (cv.IsEditingItem) { cv.CommitEdit(); } } if (filterPr.itemsDeferRefreshCount == 0) { filterPr.itemsDeferRefresh = filterPr.CollectionView.DeferRefresh(); } filterPr.itemsDeferRefreshCount++; }
/// <summary> /// Commits the current entity editing and exits the editing mode. /// </summary> /// <param name="dataItem">The entity being edited</param> /// <returns>True if a commit operation was invoked.</returns> public bool EndEdit(object dataItem) { #if FEATURE_IEDITABLECOLLECTIONVIEW IEditableCollectionView editableCollectionView = this.EditableCollectionView; if (editableCollectionView != null) { // IEditableCollectionView.CommitEdit can potentially change currency. If it does, // we don't want to attempt a second commit inside our CurrentChanging event handler. _owner.NoCurrentCellChangeCount++; this.EndingEdit = true; try { if (editableCollectionView.IsAddingNew && dataItem == editableCollectionView.CurrentAddItem) { editableCollectionView.CommitNew(); } else { editableCollectionView.CommitEdit(); } } finally { _owner.NoCurrentCellChangeCount--; this.EndingEdit = false; } return(true); } #endif IEditableObject editableDataItem = dataItem as IEditableObject; if (editableDataItem != null) { editableDataItem.EndEdit(); } return(true); }
/// <summary> /// Zatwierdzenie zmian /// </summary> private void OnCommit(object sender, RoutedEventArgs e) { string errmsg = string.Empty; if (m_mode == eDbOperation.Insert) { var endpoint = m_endpoints.CurrentAddItem as FtpEndpoint; endpoint.Instance = m_mainWnd.m_instance; SanitizeDirectories(ref endpoint); errmsg = FtpDiligentDatabaseClient.ModifyEndpoint(endpoint.GetModel(), m_mode); if (string.IsNullOrEmpty(errmsg)) { endpoint.XX = IFtpDiligentDatabaseClient.m_lastInsertedKey; m_endpoints.CommitNew(); } } else { var endpoint = m_endpoints.CurrentEditItem as FtpEndpoint; SanitizeDirectories(ref endpoint); errmsg = FtpDiligentDatabaseClient.ModifyEndpoint(endpoint.GetModel(), m_mode); if (string.IsNullOrEmpty(errmsg)) { m_endpoints.CommitEdit(); } } if (string.IsNullOrEmpty(errmsg)) { RestoreTabControl(); } else { m_mainWnd.ShowErrorInfo(eSeverityCode.Error, errmsg); } }
protected override void DeleteCore() { // Contains the same references as in SelectedEvents, // these references can change when un-doing so keep a snapshot around List <Event> previousSelection = new List <Event>(SelectedEvents); // Contains instance copies of events, this will be the old data before the do is applied. List <Event> eventsCopy = SelectedEvents.Select(d => d.DuckCopy <Event>()).ToList(); #region Do action Action doAction = delegate { // Get the view source of the events collection IEditableCollectionView eventsView = (IEditableCollectionView)EventsViewSource.View; foreach (Event calendarevent in SelectedEvents) { // Edit the view source eventsView.EditItem(calendarevent); // Move the event to the trash calendarevent.EventFolder = Folders.Trash; ClientState.Current.DataService.Update(calendarevent, "EventFolder"); // Let the world know that an event is moved to the trash EventBroker.Publish(AppEvents.UpdateEventState, calendarevent); // Commit the changes to the view eventsView.CommitEdit(); } }; #endregion #region Undo action Action undoAction = delegate { // Walk through all the events in the previous selection foreach (Event calendarevent in previousSelection) { // Get the origional event from the copied list var oldCalendarEvent = eventsCopy.Single(d => d.InternalEventId == calendarevent.InternalEventId); // Set the folder to the origional folder calendarevent.EventFolder = oldCalendarEvent.EventFolder; // Update the event ClientState.Current.DataService.Update(calendarevent, "EventFolder"); // Let the world know that an event is updated EventBroker.Publish(AppEvents.UpdateEventState, calendarevent); } // We cannot use the IEditableObject appraoch here because the document in question // probably might not be in view anymore. So instead we will refresh the whole view. EventsViewSource.View.Refresh(); }; #endregion // Add the do and undo actions to the UndoManager ClientState.Current.UndoManager.Execute(new HistoryAction(doAction, undoAction)); }
public void CommitEdit() { _collectionView.CommitEdit(); }