/// <summary> /// Creates a new item to be edited. /// </summary> /// <returns>The newly created item.</returns> public void AddItem() { // a new row may be requested before any data source is specified if (this.ItemType == null) { return; } NewItemEventArgs newItemEventArgs = new NewItemEventArgs(); this.SendNotification(Notifications.NewItemCustom, newItemEventArgs); object newItem = newItemEventArgs.NewItem ?? (from constructor in this.ItemType.GetConstructors(BindingFlags.Public | BindingFlags.Instance) where constructor.GetParameters().Length == 0 select constructor.Invoke(null)).FirstOrDefault(); if (newItem == null) { const string error = "A new item cannot be created because the type of {0} " + "does not have a parameterless constructor."; throw new MissingMemberException(string.Format(error, this.ItemType.FullName)); } // not checking of the underlying source can be added to because there may be no source at at all yet this.SendNotification(Notifications.NewItemAdded, newItem); this.Data = newItem; }
/// <summary> /// Raises the <see cref="NewItemAdding"/> event. /// </summary> /// <param name="e">The <see cref="NewItemEventArgs"/> instance containing the event data.</param> public void OnNewItemAdding(NewItemEventArgs e) { EventHandler<NewItemEventArgs> handler = this.NewItemAdding; if (handler != null) { handler(this, e); } }