private void Button_Click(object sender, RoutedEventArgs e) { IEditableCollectionViewAddNewItem viewToAddDisparateItems = catalogList.Items as IEditableCollectionViewAddNewItem; if (!viewToAddDisparateItems.CanAddNewItem) { MessageBox.Show("You cannot add items to the list."); return; } // Create a window that prompts the user to enter a new // item to sell. AddItemWindow win = new AddItemWindow(); // Create an item, depending on which RadioButton is selected. // Radio buttons correspond to book, cd, dvd, or other. LibraryItem newItem; if ((bool)book.IsChecked) { newItem = new Book("Enter the book title", "Enter an Author", "Enter a Genre", "Enter a call number", DateTime.Now + new TimeSpan(21, 0, 0, 0)); } else if ((bool)cd.IsChecked) { newItem = new MusicCD("Enter the Album", "Enter the artist", 0, "CD.******", DateTime.Now + new TimeSpan(14, 0, 0, 0)); } else if ((bool)dvd.IsChecked) { newItem = new MovieDVD("Enter the movie title", "Enter the director", "Enter the genre", new TimeSpan(), "DVD.******", DateTime.Now + new TimeSpan(7, 0, 0, 0)); } else { newItem = new LibraryItem("Enter the title", "Enter the call number", DateTime.Now + new TimeSpan(14, 0, 0, 0)); } // Add the new item to the collection by calling // IEditableCollectionViewAddNewItem.AddNewItem. // Set the DataContext of the AddItemWindow to the // returned item. win.DataContext = viewToAddDisparateItems.AddNewItem(newItem); // 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()) { viewToAddDisparateItems.CommitNew(); } else { viewToAddDisparateItems.CancelNew(); } }
private void ExecuteAddCommand(object parameter) { var speaker = new Speaker(); _editView.AddNewItem(speaker); this.RefreshCommands(); this.IsDeleteDialogOpen = false; this.CurrentState = EDIT_STATE; }
private void ExecuteAddCommand(object parameter) { var session = new SessionDto(); session.TrackIds = new ObservableCollection <int>(); _editView.AddNewItem(session); this.SetCurrentSession(session); this.RefreshCommands(); this.CurrentState = EDIT_STATE; }
/// <summary> /// Add a new item to the underlying collection. Returns the new item. /// After calling AddNewItem and changing the new item as desired, either /// <seealso cref="IEditableCollectionView.CommitNew"/> or <seealso cref="IEditableCollectionView.CancelNew"/> should be /// called to complete the transaction. /// </summary> object IEditableCollectionViewAddNewItem.AddNewItem(object newItem) { IEditableCollectionViewAddNewItem ani = ProxiedView as IEditableCollectionViewAddNewItem; if (ani != null) { return(ani.AddNewItem(newItem)); } else { throw new InvalidOperationException(SR.Get(SRID.MemberNotAllowedForView, "AddNewItem")); } }
// Token: 0x06007417 RID: 29719 RVA: 0x002130E4 File Offset: 0x002112E4 object IEditableCollectionViewAddNewItem.AddNewItem(object newItem) { IEditableCollectionViewAddNewItem editableCollectionViewAddNewItem = this.ProxiedView as IEditableCollectionViewAddNewItem; if (editableCollectionViewAddNewItem != null) { return(editableCollectionViewAddNewItem.AddNewItem(newItem)); } throw new InvalidOperationException(SR.Get("MemberNotAllowedForView", new object[] { "AddNewItem" })); }
private void button3_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog openFileDialog2 = new Microsoft.Win32.OpenFileDialog(); openFileDialog2.ShowReadOnly = true; openFileDialog2.Multiselect = true; openFileDialog2.Title = "Select file names to copy after a scenario run"; if (openFileDialog2.ShowDialog().Value) { IEditableCollectionViewAddNewItem items = listBox2.Items; if (items.CanAddNewItem) { foreach (var fi in openFileDialog2.FileNames) { items.AddNewItem(fi); } } } }