--- title: Customize Item Addition with BindingSource component ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" - "cpp" helpviewer_keywords: - "controls [Windows Forms], creating new items" - "BindingSource component [Windows Forms], customizing item addition with" - "examples [Windows Forms], BindingSource component" - "BindingSource component [Windows Forms], examples" ms.assetid: 1aae11fc-6fb2-4cb9-b3d0-e0638fe77ef0 --- # How to: Customize Item Addition with the Windows Forms BindingSource When you use a component to bind a Windows Forms control to a data source, you may find it necessary to customize the creation of new items. The component makes this straightforward by providing the event, which is typically raised when the bound control needs to create a new item. Your event handler can provide whatever custom behavior is required (for example, calling a method on a Web service or getting a new object from a class factory). > [!NOTE] > When an item is added by handling the event, the addition cannot be canceled. ## Example The following example demonstrates how to bind a control to a class factory by using a component. When the user clicks the control's new row, the event is raised. The event handler creates a new `DemoCustomer` object, which is assigned to the property. This causes the new `DemoCustomer` object to be added to the component's list and to be displayed in the new row of the control. [!code-cpp[System.Windows.Forms.DataConnector.AddingNew#1](~/samples/snippets/cpp/VS_Snippets_Winforms/System.Windows.Forms.DataConnector.AddingNew/CPP/form1.cpp#1)] [!code-csharp[System.Windows.Forms.DataConnector.AddingNew#1](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataConnector.AddingNew/CS/form1.cs#1)] [!code-vb[System.Windows.Forms.DataConnector.AddingNew#1](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataConnector.AddingNew/VB/form1.vb#1)] ## Compiling the Code This example requires: - References to the System, System.Data, System.Drawing and System.Windows.Forms assemblies. ## See also - - - - [BindingSource Component](bindingsource-component.md) - [How to: Bind a Windows Forms Control to a Type](how-to-bind-a-windows-forms-control-to-a-type.md)