Exemple #1
0
        /// <summary>
        /// Raises the <see cref="AddingNew"/> event.
        /// </summary>
        /// <param name="e">The <see cref="System.ComponentModel.AddingNewEventArgs"/> instance containing the event data.</param>
        protected virtual void OnAddingNew(AddingNewEventArgs e)
        {
            AddingNewEventHandler handler = AddingNew;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Exemple #2
0
        object IBindingList.AddNew()
        {
            AddingNewEventArgs args = new AddingNewEventArgs();

            OnAddingNew(args);

            if (args.NewObject == null)
            {
                throw new Exception("Could not determine new value to add to '{0}'.".FormatWith(CultureInfo.InvariantCulture, GetType()));
            }

            if (!(args.NewObject is JToken))
            {
                throw new Exception("New item to be added to collection must be compatible with {0}.".FormatWith(CultureInfo.InvariantCulture, typeof(JToken)));
            }

            JToken newItem = (JToken)args.NewObject;

            Add(newItem);

            return(newItem);
        }