BindingList<T>.AddNew Method

Adds a new item to the collection.

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)

public T AddNew()

Return Value

Type: T
The item added to the list.


The AllowNew property is set to false.


A public default constructor could not be found for the current item type.

The AddNew method adds a new item to the collection represented by the Items property. To add a new item, the following logic is used:

  1. The AddingNew event is automatically raised.

    This event can be programmatically handled to construct a new custom item. This is accomplished in the event handler by setting the NewObject property of the AddingNewEventArgs parameter to the new item.

    Otherwise, the new item is automatically created through its public default constructor.

  2. The position of the new item is tracked, but it is not added to the list until one of the following conditions are met:

    • The item is explicitly committed by a call to EndNew.

    • The item is implicitly committed by some other operation that changed the contents of the list, such as an insertion or removal of an item.

In contrast, calling the CancelNew method before the item is committed will cause the new item to be discarded.

This method raises the ListChanged event when the new item is committed.

The following code example demonstrates how to use the AddNew method. BindingList<T>. For the complete example, see the BindingList<T> class overview topic.

// Add the new part unless the part number contains
// spaces. In that case cancel the add.
private void button1_Click(object sender, EventArgs e)
    Part newPart = listOfParts.AddNew();

    if (newPart.PartName.Contains(" "))
        MessageBox.Show("Part names cannot contain spaces.");
        textBox2.Text = randomNumber.Next(9999).ToString();
        textBox1.Text = "Enter part name";

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft