BindingSource.Add Method

Note: This method is new in the .NET Framework version 2.0.

Adds an existing item to the internal list.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public virtual int Add (
	Object value
)
public int Add (
	Object value
)
public function Add (
	value : Object
) : int

Parameters

value

An Object to be added to the internal list.

Return Value

The zero-based index at which value was added to the underlying list represented by the List property.

Exception typeCondition

InvalidOperationException

value differs in type from the existing items in the underlying list.

The Add method refers the call to the underlying list's Add method.

The internal list must contain homogenous types. If the DataSource property has not already been set, then the first object added to the list defines the type for the list.

This method raises the ListChanged event.

The following code example uses a BindingSource component to bind a list to a DataGridView control. The list is populated by calls to the Add method.

This code example is part of a larger example provided in How to: Raise Change Notifications Using the BindingSource ResetItem Method.

private void Form1_Load(System.Object sender, System.EventArgs e)
{
    // Create and populate the list of DemoCustomer objects
    // which will supply data to the DataGridView.
    List<DemoCustomer> customerList = new List<DemoCustomer>();
    customerList.Add(DemoCustomer.CreateNewCustomer());
    customerList.Add(DemoCustomer.CreateNewCustomer());
    customerList.Add(DemoCustomer.CreateNewCustomer());

    // Bind the list to the BindingSource.
    this.customersBindingSource.DataSource = customerList;

    
    // Attach the BindingSource to the DataGridView.
    this.customersDataGridView.DataSource = 
        this.customersBindingSource;
}

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show: