private void add_Click(object sender, RoutedEventArgs e) { IEditableCollectionView editableCollectionView = itemsControl.Items as IEditableCollectionView; if (!editableCollectionView.CanAddNew) { MessageBox.Show("You cannot add items to the list."); return; } // Create a window that prompts the user to enter a new // item to sell. ChangeItemWindow win = new ChangeItemWindow(); //Create a new item to be added to the collection. win.DataContext = editableCollectionView.AddNew(); // If the user submits the new item, commit the new // object to the collection. If the user cancels // adding the new item, discard the new item. if ((bool)win.ShowDialog()) { editableCollectionView.CommitNew(); } else { editableCollectionView.CancelNew(); } }
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(); } }
private void UpdateButton_Click(object sender, RoutedEventArgs e) { // See if a row is selected and update that row if (ValidateFields() && ClaimDetails.SelectedItem != null) { string bodyPart = "00"; if (this.UseAlternateBodyPart.IsChecked ?? false) { bodyPart = "01"; } IEditableCollectionView view = ClaimDetails.Items as IEditableCollectionView; if (!view.CanAddNew) { Debug.WriteLine("Can't add new"); } Debug.WriteLine("Item selected! updating"); ItemRow row = (ItemRow)ClaimDetails.SelectedItem; row.PatientId = PatientIdInput.Text; row.Description = DescriptionTextBox.Text; row.Dos = DOSInput.Value; row.ItemFee = ItemFeeInput.Text; row.ItemNumber = ItemNumberInput.Text; row.BodyPart = bodyPart; ClaimDetails.Items.Refresh(); clearEntryFields(false); } }
protected override int FindIndex(object item, object seed, IComparer comparer, int low, int high) { IEditableCollectionView editableCollectionView = this._view as IEditableCollectionView; if (editableCollectionView != null) { if (editableCollectionView.NewItemPlaceholderPosition == NewItemPlaceholderPosition.AtBeginning) { ++low; if (editableCollectionView.IsAddingNew) { ++low; } } else { if (editableCollectionView.IsAddingNew) { --high; } if (editableCollectionView.NewItemPlaceholderPosition == NewItemPlaceholderPosition.AtEnd) { --high; } } } return(base.FindIndex(item, seed, comparer, low, high)); }
public void Refresh() { { CameraTabs.Clear(); CameraTabs.Add(SimpleIoc.Default.GetInstance<CamerasViewModel>()); foreach (CameraViewModel scvm in SimpleIoc.Default.GetAllCreatedInstances<CameraViewModel>()) { CameraTabs.Add(scvm); } IEditableCollectionView itemsView = (IEditableCollectionView)CollectionViewSource.GetDefaultView(CameraTabs); itemsView.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtEnd; } { MotionControllerTabs.Clear(); MotionControllerTabs.Add(SimpleIoc.Default.GetInstance<MotionControllersViewModel>()); foreach (MotionControllerViewModel mcvm in SimpleIoc.Default.GetAllCreatedInstances<MotionControllerViewModel>()) { MotionControllerTabs.Add(mcvm); } IEditableCollectionView itemsView = (IEditableCollectionView)CollectionViewSource.GetDefaultView(MotionControllerTabs); itemsView.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtEnd; } { ServerTabs.Clear(); ServerTabs.Add(SimpleIoc.Default.GetInstance<ServerViewModel>()); IEditableCollectionView itemsView = (IEditableCollectionView)CollectionViewSource.GetDefaultView(ServerTabs); itemsView.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtEnd; } } // Refresh
protected override int FindIndex(object item, object seed, IComparer comparer, int low, int high) { // root group needs to adjust the bounds of the search to exclude the // placeholder and new item (if any) IEditableCollectionView iecv = _view as IEditableCollectionView; if (iecv != null) { if (iecv.NewItemPlaceholderPosition == NewItemPlaceholderPosition.AtBeginning) { ++low; if (iecv.IsAddingNew) { ++low; } } else { if (iecv.IsAddingNew) { --high; } if (iecv.NewItemPlaceholderPosition == NewItemPlaceholderPosition.AtEnd) { --high; } } } return(base.FindIndex(item, seed, comparer, low, high)); }
public void ICVF_Remove() { EntitySet <City> entitySet; EntityCollection <City> entityCollection = this.CreateEntityCollection(out entitySet); IEditableCollectionView view = this.GetIECV(entityCollection); City city = (City)view.AddNew(); city.Name = "Des Moines"; city.CountyName = "King"; city.StateName = "WA"; view.CommitNew(); entityCollection.Add(this.CreateLocalCity("Normandy Park")); entityCollection.Add(this.CreateLocalCity("SeaTac")); // This one was added through the view and will be removed from both view.Remove(city); Assert.IsFalse(entityCollection.Contains(city), "EntityCollection should no longer contain the first entity."); Assert.IsFalse(entitySet.Contains(city), "EntitySet should no longer contain the first entity."); // This one was added directly and will only be removed for the collection city = entityCollection.ElementAt(1); view.Remove(city); Assert.IsFalse(entityCollection.Contains(city), "EntityCollection should no longer contain the entity at index 1."); Assert.IsTrue(entitySet.Contains(city), "EntitySet should still contain the entity at index 1."); }
/// <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); }
private void remove_Click(object sender, RoutedEventArgs e) { PurchaseItem item = itemsControl.SelectedItem as PurchaseItem; if (item == null) { MessageBox.Show("No Item is selected"); return; } IEditableCollectionView editableCollectionView = itemsControl.Items as IEditableCollectionView; if (!editableCollectionView.CanRemove) { MessageBox.Show("You cannot remove items from the list."); return; } if (MessageBox.Show("Are you sure you want to remove " + item.Description, "Remove Item", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { editableCollectionView.Remove(itemsControl.SelectedItem); } }
private void listBox_PreviewMouseDown(object sender, MouseButtonEventArgs e) { mouseClickedOnListBox = true; DependencyObject dep = (DependencyObject)e.OriginalSource; e.Handled = true; while ((dep != null) && !(dep is System.Windows.Controls.ListBoxItem)) { dep = System.Windows.Media.VisualTreeHelper.GetParent(dep); } if (dep == null) { return; } int index = listBox.ItemContainerGenerator.IndexFromContainer(dep); listBox.SelectedIndex = index; this.confirmCompletion(false); // Remove selected item from list if tags autocomplete if (this.controller.autocompleteType == 1) { IEditableCollectionView items = listBox.Items; //Cast to interface if (items.CanRemove) { items.RemoveAt(index); } } }
/// <summary> /// Puts the entity into editing mode if possible /// </summary> /// <param name="dataItem">The entity to edit</param> /// <returns>True if editing was started</returns> public bool BeginEdit(object dataItem) { if (dataItem == null) { return(false); } IEditableCollectionView editableCollectionView = this.EditableCollectionView; if (editableCollectionView != null) { if (editableCollectionView.IsEditingItem && (dataItem == editableCollectionView.CurrentEditItem)) { return(true); } else { editableCollectionView.EditItem(dataItem); return(editableCollectionView.IsEditingItem); } } IEditableObject editableDataItem = dataItem as IEditableObject; if (editableDataItem != null) { editableDataItem.BeginEdit(); return(true); } return(true); }
/// <summary>Sends a request to activate a control and initiate its single, unambiguous action.</summary> // Token: 0x060025EA RID: 9706 RVA: 0x000B5990 File Offset: 0x000B3B90 void IInvokeProvider.Invoke() { this.EnsureEnabled(); object item = base.Item; if (this.GetWrapperPeer() == null) { this.OwningDataGrid.ScrollIntoView(item); } bool flag = false; UIElement wrapper = base.GetWrapper(); if (wrapper != null) { IEditableCollectionView items = this.OwningDataGrid.Items; if (items.CurrentEditItem == item) { flag = this.OwningDataGrid.CommitEdit(); } else if (this.OwningDataGrid.Columns.Count > 0) { DataGridCell dataGridCell = this.OwningDataGrid.TryFindCell(item, this.OwningDataGrid.Columns[0]); if (dataGridCell != null) { this.OwningDataGrid.UnselectAll(); dataGridCell.Focus(); flag = this.OwningDataGrid.BeginEdit(); } } } if (!flag && !this.IsNewItemPlaceholder) { throw new InvalidOperationException(SR.Get("DataGrid_AutomationInvokeFailed")); } }
/// <summary> /// Puts the entity into editing mode if possible /// </summary> /// <param name="dataItem">The entity to edit</param> /// <returns>True if editing was started</returns> public bool BeginEdit(object dataItem) { if (dataItem == null) { return(false); } #if FEATURE_IEDITABLECOLLECTIONVIEW IEditableCollectionView editableCollectionView = this.EditableCollectionView; if (editableCollectionView != null) { if ((editableCollectionView.IsEditingItem && (dataItem == editableCollectionView.CurrentEditItem)) || (editableCollectionView.IsAddingNew && (dataItem == editableCollectionView.CurrentAddItem))) { return(true); } else { editableCollectionView.EditItem(dataItem); return(editableCollectionView.IsEditingItem); } } #endif IEditableObject editableDataItem = dataItem as IEditableObject; if (editableDataItem != null) { editableDataItem.BeginEdit(); return(true); } return(true); }
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> /// Move <seealso cref="CurrentItem"/> to the given item. /// If the item is not found, move to BeforeFirst. /// </summary> /// <param name="item">Move CurrentItem to this item.</param> /// <returns>True if <seealso cref="CurrentItem"/> points to an item within the view.</returns> public virtual bool MoveCurrentTo(object item) { VerifyRefreshNotDeferred(); // if already on item, don't do anything if (object.Equals(CurrentItem, item)) { // also check that we're not fooled by a false null _currentItem if (item != null || IsCurrentInView) { return(IsCurrentInView); } } int index = -1; #if FEATURE_IEDITABLECOLLECTIONVIEW IEditableCollectionView ecv = this as IEditableCollectionView; bool isNewItem = ecv != null && ecv.IsAddingNew && object.Equals(item, ecv.CurrentAddItem); #elif FEATURE_ICOLLECTIONVIEW_FILTER bool isNewItem = false; #endif #if FEATURE_ICOLLECTIONVIEW_FILTER if (isNewItem || item == null || PassesFilter(item)) #endif { // if the item is not found IndexOf() will return -1, and // the MoveCurrentToPosition() below will move current to BeforeFirst index = IndexOf(item); } return(MoveCurrentToPosition(index)); }
private void Update_Click(object sender, RoutedEventArgs e) { if (_currentItem == null) { return; } var generator = new Generator { DomainField = { Text = _currentItem[0] }, UsernameField = { Text = _currentItem[1] }, OutputField = { Text = _currentItem[2] }, TimeUpdatedField = { Text = _currentItem[3] }, CommentField = { Text = _currentItem[4] }, TypeSelector = { Text = _currentItem[5] } }; generator.ShowDialog(); if (generator.Domain == null) { return; } Account.Storage.DomainList.Add(generator.Domain); IEditableCollectionView items = ListTable.Items; if (items.CanRemove) { items.Remove(ListTable.SelectedItem); } RefreshList(); _modified = true; _currentItem = null; }
public void Initialize() { this._dds = new DomainDataSource(); this._dds.Loaded += new RoutedEventHandler(this.DomainDataSourceLoaded); this._dds.LoadingData += new EventHandler <OpenRiaServices.Controls.LoadingDataEventArgs>(this.DomainDataSourceLoadingData); this._dds.LoadedData += new EventHandler <LoadedDataEventArgs>(this.DomainDataSourceLoadedData); this._dds.SubmittingChanges += new EventHandler <SubmittingChangesEventArgs>(this.DomainDataSourceSubmittingChanges); this._dds.SubmittedChanges += new EventHandler <SubmittedChangesEventArgs>(this.DomainDataSourceSubmittedChanges); this._view = this._dds.DataView; this._view.PageChanged += this.ViewPageChanged; this._collectionView = this._view; this._collectionView.CollectionChanged += this.ViewCollectionChanged; this._editableCollectionView = this._view; this._pagedCollectionView = this._view; this._comboBox = new ComboBox { Name = "_comboBox" }; this._comboBox.Loaded += new RoutedEventHandler(this.ComboBoxLoaded); this._textBox = new TextBox { Name = "_textBox" }; this._textBox.Loaded += new RoutedEventHandler(this.TextBoxLoaded); this.ResetLoadState(); this.ResetPageChanged(); this.ResetSubmitState(); this._asyncEventFailureMessage = null; }
/// <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(); }
private void MainGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e) { IEditableCollectionView iecv = CollectionViewSource.GetDefaultView((sender as DataGrid).ItemsSource) as IEditableCollectionView; if (iecv.IsAddingNew) { Dispatcher.Invoke(new DispatcherOperationCallback(ResetNewItemTemplate), DispatcherPriority.ApplicationIdle, MainGrid); } }
public IgnorePairCommand(ObservableCollection <DuplPairViewModel> resultList, IEditableCollectionView collectionView, List <DuplPairViewModel> ignoreList, int index) { _resultList = resultList; _collectionView = collectionView; _ignoreList = ignoreList; _index = index; //_dispatcher = dispatcher; }
public DeleteOtherFromPairCommand(ImageInfoClass currentInfo, DuplPairViewModel result, ObservableCollection <DuplPairViewModel> resultList, IEditableCollectionView collectionView, int index) { _forSaveInfo = currentInfo; _result = result; _resultList = resultList; _collectionView = collectionView; _index = index; }
private void DeleteLabel_Click(object sender, RoutedEventArgs e) { IEditableCollectionView items = LabelsListBox.Items; //Cast to interface if (items.CanRemove) { items.Remove(LabelsListBox.SelectedItem); } }
/// <summary> /// Adds a new item to the collection. /// </summary> /// <returns></returns> Object IEditableCollectionView.AddNew() { IEditableCollectionView iEditableCollectionView = this.currentView as IEditableCollectionView; if (iEditableCollectionView == null) { throw new InvalidOperationException(ExceptionMessage.Format(ExceptionMessages.MemberNotAllowedForView, "AddNew")); } return(iEditableCollectionView.AddNew()); }
/// <summary> /// Ends the add transaction and saves the pending new item. /// </summary> void IEditableCollectionView.CommitNew() { IEditableCollectionView iEditableCollectionView = this.currentView as IEditableCollectionView; if (iEditableCollectionView == null) { throw new InvalidOperationException(ExceptionMessage.Format(ExceptionMessages.MemberNotAllowedForView, "CommitNew")); } iEditableCollectionView.CommitNew(); }
/// <summary> /// Begins an edit transaction of the specified item. /// </summary> /// <param name="item">The item to edit.</param> void IEditableCollectionView.EditItem(Object item) { IEditableCollectionView iEditableCollectionView = this.currentView as IEditableCollectionView; if (iEditableCollectionView == null) { throw new InvalidOperationException(ExceptionMessage.Format(ExceptionMessages.MemberNotAllowedForView, "EditItem")); } iEditableCollectionView.EditItem(item); }
/// <summary> /// Removes the item at the specified position from the collection. /// </summary> /// <param name="index">The position of the item to remove.</param> void IEditableCollectionView.RemoveAt(Int32 index) { IEditableCollectionView iEditableCollectionView = this.currentView as IEditableCollectionView; if (iEditableCollectionView == null) { throw new InvalidOperationException(ExceptionMessage.Format(ExceptionMessages.MemberNotAllowedForView, "RemoveAt")); } iEditableCollectionView.RemoveAt(index); }
private void ItemsDataGrid_LoadingRow(object sender, DataGridRowEventArgs e) { IEditableCollectionView itemsView = ItemsDataGrid.Items; if (ItemsDataGrid.Items.Count == 31 && itemsView.IsAddingNew == true) { itemsView.CommitNew(); ItemsDataGrid.CanUserAddRows = false; } }
/// Remove selected items from the ListBox. private void Button_Click(object sender, RoutedEventArgs e) { IEditableCollectionView items = ma_ListView.Items; //Cast to interface if (items.CanRemove) { items.Remove(ma_ListView.SelectedItem); TotalPrice -= panier.prix_total; } }
// ****************************************************************** /// <summary> /// This virtual method is called when ApplicationCommands.Paste command is executed. /// </summary> /// <param name="target"></param> /// <param name="args"></param> protected virtual void OnExecutedPaste(object sender, ExecutedRoutedEventArgs args) { // parse the clipboard data List <string[]> rowData = ClipboardHelper.ParseClipboardData(); bool hasAddedNewRow = false; // call OnPastingCellClipboardContent for each cell int minRowIndex = Math.Max(Items.IndexOf(CurrentItem), 0); int maxRowIndex = Items.Count - 1; int minColumnDisplayIndex = (SelectionUnit != DataGridSelectionUnit.FullRow) ? Columns.IndexOf(CurrentColumn) : 0; int maxColumnDisplayIndex = Columns.Count - 1; int rowDataIndex = 0; for (int i = minRowIndex; i <= maxRowIndex && rowDataIndex < rowData.Count; i++, rowDataIndex++) { if (CanUserAddRows && i == maxRowIndex) { // add a new row to be pasted to ICollectionView cv = CollectionViewSource.GetDefaultView(Items); IEditableCollectionView iecv = cv as IEditableCollectionView; if (iecv != null) { hasAddedNewRow = true; iecv.AddNew(); if (rowDataIndex + 1 < rowData.Count) { // still has more items to paste, update the maxRowIndex maxRowIndex = Items.Count - 1; } } } else if (i == maxRowIndex) { continue; } int columnDataIndex = 0; for (int j = minColumnDisplayIndex; j < maxColumnDisplayIndex && columnDataIndex < rowData[rowDataIndex].Length; j++, columnDataIndex++) { DataGridColumn column = ColumnFromDisplayIndex(j); string propertyName = ((column as DataGridBoundColumn).Binding as Binding).Path.Path; object item = Items[i]; object value = rowData[rowDataIndex][columnDataIndex]; PropertyInfo pi = item.GetType().GetProperty(propertyName); if (pi != null) { object convertedValue = Convert.ChangeType(value, pi.PropertyType); item.GetType().GetProperty(propertyName).SetValue(item, convertedValue, null); } column.OnPastingCellClipboardContent(item, rowData[rowDataIndex][columnDataIndex]); } } }
public EditableCollectionView(IEnumerable <T> editableItems) { List <EditableItem <T> > list = new List <EditableItem <T> >(); foreach (var item in editableItems) { list.Add(new EditableItem <T>(item)); } _collectionView = CollectionViewSource.GetDefaultView(list) as IEditableCollectionView; }
public async void Initialize(IServicePool pool) { _isInititializing = true; this.State = "ReadOnly"; if (Application.Current != null && Application.Current.MainWindow != null && !DesignerProperties.GetIsInDesignMode(Application.Current.MainWindow)) { _speakerService = pool.GetService<ISpeakersService>(); this.SaveCommand = new DelegateCommand(this.CanExecuteSaveCommand, this.ExecuteSaveCommand); var list = await _speakerService.GetSpeakerListAsync(); this.SpeakerList = new ObservableCollection<SpeakerDto>(list); this.CurrentSpeaker = this.SpeakerList[0]; this.SpeakerListView = new ListCollectionView(this.SpeakerList); this.SpeakerListView.CurrentChanged += SpeakerListView_CurrentChanged; this.SpeakerListView.MoveCurrentTo(this.SpeakerList[1]); //this.SpeakerListView.Filter = item => ((Speaker)item).FirstName.StartsWith("C"); _speakerEditView = this.SpeakerListView as IEditableCollectionView; } _isInititializing = false; }