Provides data for an event that signals the adding of a new object to a list, allowing any event handler to supply the new object. If no event handler supplies a new object to use, the list should create one itself.
Inheritance: System.EventArgs
Example #1
0
 private void bindingSource_AddingNew(object sender, AddingNewEventArgs e)
 {
     if (enableChangeTracking)
     {
         var service = CreateWorkTrackService();
         var project = service.CreateProject();
         project.Id = Guid.NewGuid();
         e.NewObject = project;
     }
 }
 private void StrataBindingSource_AddingNew(object sender, AddingNewEventArgs e)
 {
     //because we want to store a list of samplegroups for each strata
     //lets create a list and store it in the Tag.
     //the tag is a general term for a property on an object that is
     // designed to attatche extera data to that object that, fufills
     //an unexpected need.
     var newStrata = new StratumDO();
     newStrata.Tag = new List<SampleGroupDO>();
     e.NewObject = newStrata;
 }
Example #3
0
        private void Binding_AddingNew(object sender, AddingNewEventArgs e)
        {
            var line = new PlanLine()
            {
                StartedDate = dtpStartedDate.Value,
                PlannedEndDate = dtpPlannedEndDate.Value,
                ActualEndDate = dtpActualEndDate.Value,
                State = PlanLineState.New
            };

            e.NewObject = line;
        }
Example #4
0
 //private void btnArtSave_Click(object sender, EventArgs e)// Salvar articulo
 //{
 //    articulosTableAdapter.Update(dsArticulos);
 //    articulosTableAdapter.Fill(dsArticulos.articulos);
 //    articulosTableAdapter1.Fill(dsArticulosCombo.articulos);
 //    comboBox1_SelectedIndexChanged(listArtCompuestos, EventArgs.Empty);
 //}
 private void articulosBindingSource_AddingNew(object sender, AddingNewEventArgs e)
 {
     try
     {
         if (((BindingSource)sender).Current != null)
         {
             if (((BindingSource)sender).Current.GetType() == typeof(DataRowView))
             {
                 articulosTableAdapter.Update(((DataRowView)((BindingSource)sender).Current).Row);
                 articulosTableAdapter1.Fill(dsArticulosCombo.articulos);
             }
         }
     }
     catch (Exception ex)
     {
         LoggerProxy.ErrorSinBD(ex.Message + "-" + ex.StackTrace);
     }
     dgvCompuestoPor.ClearSelection();
 }
 private void OrderlineList_AddingNew(object sender, AddingNewEventArgs e)
 {
     OwnerForm.PerformActionWithLoading(new Action(() =>
     {
         System.Threading.Thread.Sleep(5000);
         var newObject =new PurchaseOrderlineEntity()
         {
             OrderlineId = -1,
             OrderId = CurrentOrder.OrderId,
             ChildList = new BindingList<LoanEntity>()
         };
         newObject.ChildList.AddingNew += ChildList_AddingNew;
         e.NewObject = newObject;
     }));
 }
Example #6
0
 protected virtual void OnAddingNew(AddingNewEventArgs e)
 {
     throw new NotImplementedException();
 }
 void ChildList_AddingNew(object sender, AddingNewEventArgs e)
 {
     var newObject = new LoanEntity()
     {
         OrderlineId = -1
     };
     e.NewObject = newObject;
 }
Example #8
0
 void _storeGrades_AddingNew(object sender, AddingNewEventArgs e)
 {
     throw new NotImplementedException();
 }
Example #9
0
 void OnAddingNew(object sender, AddingNewEventArgs e)
 {
     e.NewObject = _cmd.CreateParameter("", "");
 }
Example #10
0
 void SegmentList_AddingNew(object sender, AddingNewEventArgs e)
 {
     e.NewObject = new Segment("");
 }
 void _list_AddingNew(object sender, AddingNewEventArgs e)
 {
     e.NewObject = new StudentAddress();
     ((StudentAddress)e.NewObject).evtIsSavable += new IsSavableHandler(s_evtIsSavable);
 }
		/// <summary>
		/// Adds a new item to the list.
		/// </summary>
		/// <returns>The item added to the list (wrapped in an <see cref="ObjectView"/>).</returns>
		/// <exception cref="T:System.Data.DataException"><see cref="P:System.ComponentModel.IBindingList.AllowNew"></see> is false. </exception>
		public object AddNew()
		{
			Lock();

			ObjectView wrapper = null;

			try
			{
				if (!this.allowNew)
					throw new DataException("AllowNew is set to false.");

				AddingNewEventArgs args = new AddingNewEventArgs();
				OnAddingNew(args);
				object newItem = args.NewObject;

				if (newItem == null)
				{
					if (this.itemType == null)
						throw new InvalidOperationException("The list item type must be set first.");

					newItem = Activator.CreateInstance(this.itemType);
				}
				else
				{
					if (this.ItemType == null)
						this.ItemType = newItem.GetType();
					else if (newItem.GetType() != this.ItemType)
						throw new ArgumentException("Added item type is different from list item type.");
				}

				wrapper = new ObjectView(newItem);

				// If an item was previously added with AddNew() but has not yet been committed with item.EndEdit(), commit it now.
				if (newItemPending != null)
					FinishAddNew();

				this.newItemPending = wrapper;

				// If the item type is IEditable object, a newly added item will be removed from the list if IEditableObject.CancelEdit is called before
				// the next call to AddNew().  When IEditableObject.EndEdit() is called, ListChanged+ItemAdded is raised again for the same item.
				if (this.isEditableObject)
				{
					((IEditableObjectEvents)this.newItemPending).Ended += new EventHandler(editableListItem_Ended);
					((IEditableObjectEvents)this.newItemPending).Cancelled += new EventHandler(editableListItem_Cancelled);
				}

				this.Add(newItem);
			}
			finally
			{
				Unlock();
			}

			RaiseEvents();

			return wrapper;
		}
        public void TestInterfaceProxyEvent()
        {
            Duck duck = new Duck();
            IInterface proxy = DuckTyping.Cast<IInterface>(duck);

            object sender = this;
            AddingNewEventArgs e = new AddingNewEventArgs();

            EventHandler eventHandler = new EventHandler(this.EventHandlerMethod);
            AddingNewEventHandler addingNewEventHandler = new AddingNewEventHandler(this.AddingNewEventHandlerMethod);

            m_Sender = null;
            m_EventArgs = null;
            proxy.Event += eventHandler;
            duck.RaiseEvent(sender, e);
            Assert.AreEqual(sender, m_Sender, "Proxy class did not properly forward adding of an event handler.");

            m_Sender = null;
            m_EventArgs = null;
            proxy.Event -= eventHandler;
            duck.RaiseEvent(sender, e);
            Assert.IsNull(m_Sender, "Proxy class did not properly forward removing of an event handler.");

            m_Sender = null;
            m_EventArgs = null;
            proxy.CovariantEvent += addingNewEventHandler;
            duck.RaiseCovariantEvent(sender, e);
            Assert.AreEqual(sender, m_Sender, "Proxy class did not properly forward adding of an event handler to a covariant event.");

            m_Sender = null;
            m_EventArgs = null;
            proxy.CovariantEvent -= addingNewEventHandler;
            duck.RaiseCovariantEvent(sender, e);
            Assert.IsNull(m_Sender, "Proxy class did not properly forward removing of an event handler from a covariant event.");

            m_Sender = null;
            m_EventArgs = null;
            proxy.ContravariantEvent += eventHandler;
            duck.RaiseContravariantEvent(sender, e);
            Assert.AreEqual(sender, m_Sender, "Proxy class did not properly forward adding of an event handler to a contravariant event.");

            m_Sender = null;
            m_EventArgs = null;
            proxy.ContravariantEvent -= eventHandler;
            duck.RaiseContravariantEvent(sender, e);
            Assert.IsNull(m_Sender, "Proxy class did not properly forward removing of an event handler from a contravariant event.");
        }
Example #14
0
        private void categoriasBindingSource_AddingNew(object sender, AddingNewEventArgs e)
        {
            try
            {
                if (((BindingSource)sender).Current != null)
                {
                    if (((BindingSource)sender).Current.GetType() == typeof(DataRowView))
                    {
                        categoriasTableAdapter.Update(((DataRowView)((BindingSource)sender).Current).Row);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerProxy.ErrorSinBD(ex.Message + "-" + ex.StackTrace);

                lblCat_msjSalida.Visible = true;
                lblCat_msjSalida.ForeColor = Color.Red;
                if (ex.Message.Contains("FK_habitaciones_categorias"))
                {
                    lblCat_msjSalida.Text = "No se puede Eliminar la categoria, ya que esta asignada a alguna Habitación.";
                }
                else
                    lblCat_msjSalida.Text = ex.Message;
                categoriasTableAdapter.Fill(dsCategorias.categorias);

            }
        }
Example #15
0
 private void OnAddingNewToBindingSource(object sender, AddingNewEventArgs e)
 {
   if (projectListDataGridView.Rows.Count == source.Count) // http://stackoverflow.com/a/2363918/492
   {
     source.RemoveAt(source.Count - 1);
   }
 }
Example #16
0
 private void tiposCuentasGastosBindingSource_AddingNew(object sender, AddingNewEventArgs e)
 {
     try
     {
         tiposCuentasGastosTableAdapter.Update(dsTiposCuentasGastos.tiposCuentasGastos);
     }
     catch (Exception ex)
     {
         LoggerProxy.ErrorSinBD(ex.Message + "-" + ex.StackTrace);
         tiposCuentasGastosTableAdapter.Fill(dsTiposCuentasGastos.tiposCuentasGastos);
         MessageBox.Show(ex.Message + "-" + ex.StackTrace);
     }
 }
 void columnBindingSource_AddingNew(object sender, AddingNewEventArgs e)
 {
   //Column c = new Column(null);
   ColumnWithTypeDescriptor c = new ColumnWithTypeDescriptor();
   c.OwningTable = tableNode.Table;
   e.NewObject = c;
   c.DataType = "varchar(10)";
 }
Example #18
0
 /// <summary>
 /// Raises the AddingNew event.
 /// </summary>
 protected virtual void OnAddingNew(AddingNewEventArgs e) => _onAddingNew?.Invoke(this, e);
 protected virtual new void OnAddingNew(AddingNewEventArgs e)
 {
 }
 private void itemsBindingSource_AddingNew(object sender, System.ComponentModel.AddingNewEventArgs e)
 {
 }
		/// <summary>
		/// Raises the <see cref="AddingNew"/> event.
		/// </summary>
		/// <remarks>
		/// When overriding this method, you should call the base implementation to assure that the event is raised.
		/// </remarks>
		/// <param name="args">The <see cref="System.ComponentModel.AddingNewEventArgs"/> instance containing the event data.</param>
		protected virtual void OnAddingNew(AddingNewEventArgs args)
		{
			if (addingNewEvent != null)
				addingNewEvent(this, args);
		}
Example #22
0
 private void sociosBindingSource_AddingNew(object sender, AddingNewEventArgs e)
 {
     try
     {
         if (((BindingSource)sender).Current != null)
         {
             if (((BindingSource)sender).Current.GetType() == typeof(DataRowView))
             {
                 sociosTableAdapter.Update(((DataRowView)((BindingSource)sender).Current).Row);
             }
         }
     }
     catch (Exception ex)
     {
         LoggerProxy.ErrorSinBD(ex.Message + "-" + ex.StackTrace);
         sociosTableAdapter.Fill(dsSocios.socios);
     }
 }
Example #23
0
 private void productsBindingSource_AddingNew(object sender, AddingNewEventArgs e)
 {
     this.productCodeTextBox.ReadOnly = false;
 }
Example #24
0
 private void tarifasBindingSource_AddingNew(object sender, AddingNewEventArgs e)
 {
     try
     {
         if (((BindingSource)sender).Current != null)
         {
             if (((BindingSource)sender).Current.GetType() == typeof(DataRowView))
             {
                 tarifasTableAdapter.Update(((DataRowView)((BindingSource)sender).Current).Row);
                 tarifasTableAdapter.Fill(dsTarifas.tarifas);
             }
         }
     }
     catch (Exception ex)
     {
         LoggerProxy.ErrorSinBD(ex.Message + "-" + ex.StackTrace);
         //tarifasTableAdapter.Update(dsTarifas);
         //tarifasTableAdapter.Fill(dsTarifas.tarifas);
         MessageBox.Show("Error al ingresar un dato. Verifique el siguiente mensaje: \r\n" + ex.Message);
     }
     dgvCompuestoPor.ClearSelection();
 }
 private void AddingNewEventHandlerMethod(object sender, AddingNewEventArgs e)
 {
     m_Sender = sender;
     m_EventArgs = e;
 }
Example #26
0
 private void cIKKBindingSource_AddingNew(object sender, AddingNewEventArgs e)
 {
     //e.NewObject = eCAFEDataSetCIKK.CIKK.AddCIKKRow();
     cIKKBindingSource.ResetBindings(true);
 }
Example #27
0
 private void bevetelSorBindingSource_AddingNew(object sender, AddingNewEventArgs e)
 {
     e.NewObject = new BevetelSor();
     ((BevetelSor)e.NewObject).BEVETEL_FEJ_ID = AktBevId;
     ((BevetelSor)e.NewObject).FELADVA = 0;
 }
Example #28
0
 private void lITKISZBindingSource_AddingNew(object sender, AddingNewEventArgs e)
 {
     e.NewObject = eCAFEDataSetCIKK.LIT_KISZ.AddLIT_KISZRow((int)((DataRowView)cIKKBindingSource.Current)["CIKK_ID"], "", 0, 0);
 }
Example #29
0
		void BindingSourceAddingNew(object sender, AddingNewEventArgs e)
		{
			SettingsEntry entry = new SettingsEntry(this);
			entry.Type = typeof(string);
			e.NewObject = entry;
		}
Example #30
0
		public virtual object AddNew ()
		{
			if (!AllowEdit)
				throw new InvalidOperationException ("Item cannot be added to a read-only or fixed-size list.");
			if (!AllowNew) 
				throw new InvalidOperationException ("AddNew is set to false.");

			EndEdit ();

			AddingNewEventArgs args = new AddingNewEventArgs ();
			OnAddingNew (args);

			object new_object = args.NewObject;
			if (new_object != null) {
				if (!item_type.IsAssignableFrom (new_object.GetType ()))
					throw new InvalidOperationException ("Objects added to the list must all be of the same type.");
			} else if (list is IBindingList) {
				object newObj = ((IBindingList)list).AddNew ();
				add_pending = true;
				pending_add_index = list.IndexOf (newObj);
				return newObj;
			} else if (!item_has_default_ctor)
				throw new InvalidOperationException ("AddNew cannot be called on '" + item_type.Name +
						", since it does not have a public default ctor. Set AllowNew to true " +
						", handling AddingNew and creating the appropriate object.");
			else // fallback to default .ctor
				new_object = Activator.CreateInstance (item_type);

			int idx = list.Add (new_object);
			if (raise_list_changed_events && !list_is_ibinding)
				OnListChanged (new ListChangedEventArgs (ListChangedType.ItemAdded, idx));

			add_pending = true;
			pending_add_index = idx;

			return new_object;
		}
Example #31
0
 private void Bs_AddingNew(object sender, AddingNewEventArgs e)
 {
     e.NewObject = new Negocio.Modelo.Cliente();
 }
Example #32
0
        ///////////////////////////////////////////////////////////////////////////////
        //
        // IBindingList interface
        //
        ///////////////////////////////////////////////////////////////////////////////

        /// <include file='doc\BindingSource.uex' path='docs/doc[@for="BindingSource.AddNew"]/*' />
        public virtual object AddNew() {
            // Throw if adding new items has been disabled
            if (!AllowNewInternal(false)) {
                throw new InvalidOperationException(SR.GetString(SR.BindingSourceBindingListWrapperAddToReadOnlyList));
            }

            if (!AllowNewInternal(true)) {
                throw new InvalidOperationException(SR.GetString(
                    SR.BindingSourceBindingListWrapperNeedToSetAllowNew,
                    itemType == null ? "(null)" : itemType.FullName
                    ));
            }

            // Remember this since EndEdit() below will clear it
            int saveAddNew = this.addNewPos;

            // Commit any uncomitted list changes now
            EndEdit();

            // We just committed a new item; mimic DataView and fire an ItemAdded event for it here
            if (saveAddNew != -1) {
                OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, saveAddNew));
            }

            // Raise the AddingNew event in case listeners want to supply the new item for us
            AddingNewEventArgs addingNew = new AddingNewEventArgs();
            int oldCount = List.Count;
            OnAddingNew(addingNew);
            object addNewItem = addingNew.NewObject;

            //
            // If no item came back from AddingNew event, we must create the new item ourselves...
            //
            if (addNewItem == null) {
                // If the inner list is an IBindingList, let it create and add the new item for us.
                // Then make the new item the current item (...assuming, as CurrencyManager does,
                // that the new item was added at the *bottom* of the list).
                if (isBindingList) {
                    addNewItem = (List as IBindingList).AddNew();
                    this.Position = this.Count - 1;
                    return addNewItem;
                }

                // Throw if we don't know how to create items of the current item type
                if (this.itemConstructor == null) {
                    throw new InvalidOperationException(SR.GetString(
                        SR.BindingSourceBindingListWrapperNeedAParameterlessConstructor,
                        itemType == null ? "(null)" : itemType.FullName
                        ));
                }

                // Create new item using default ctor for current item type
                addNewItem = this.itemConstructor.Invoke(null);
            }

            if (List.Count > oldCount) {
                // If event handler has already added item to list, then simply record the item's position
                this.addNewPos = this.Position;
            }
            else {
                // If event handler has not yet added item to list, then add it
                // ourselves, make it the current item, and record its position.
                this.addNewPos = this.Add(addNewItem);
                this.Position = this.addNewPos;
            }

            return addNewItem;
        }
Example #33
0
 private void SubProgressBars_AddingNew(object sender, AddingNewEventArgs e)
 {
 }
Example #34
0
 /// <include file='doc\BindingSource.uex' path='docs/doc[@for="BindingSource.OnAddingNew"]/*' />
 protected virtual void OnAddingNew(AddingNewEventArgs e) {
     AddingNewEventHandler eh = (AddingNewEventHandler) Events[EVENT_ADDINGNEW];
     if (eh != null)
         eh(this, e);
 }