BindingList<T> Constructors

Definition

Initializes a new instance of the BindingList<T> class.

Overloads

BindingList<T>()

Initializes a new instance of the BindingList<T> class using default values.

BindingList<T>(IList<T>)

Initializes a new instance of the BindingList<T> class with the specified list.

BindingList<T>()

Source:
BindingList.cs
Source:
BindingList.cs
Source:
BindingList.cs

Initializes a new instance of the BindingList<T> class using default values.

C#
public BindingList();

Examples

The following code example demonstrates how to construct a new BindingList<T>. For the complete example, see the BindingList<T> class overview topic.

C#
    // Declare a new BindingListOfT with the Part business object.
    BindingList<Part> listOfParts; 
    private void InitializeListOfParts()
    {
        // Create the new BindingList of Part type.
        listOfParts = new BindingList<Part>();

        // Allow new parts to be added, but not removed once committed.        
        listOfParts.AllowNew = true;
        listOfParts.AllowRemove = false;

        // Raise ListChanged events when new parts are added.
        listOfParts.RaiseListChangedEvents = true;

        // Do not allow parts to be edited.
        listOfParts.AllowEdit = false;
        
        // Add a couple of parts to the list.
        listOfParts.Add(new Part("Widget", 1234));
        listOfParts.Add(new Part("Gadget", 5647));
    }

Remarks

The following table shows initial property values for an instance of BindingList<T> class.

Property Initial Value
AllowEdit true
AllowNew true if the list type has a parameterless constructor; otherwise, false.
AllowRemove true
RaiseListChangedEvents true

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

BindingList<T>(IList<T>)

Source:
BindingList.cs
Source:
BindingList.cs
Source:
BindingList.cs

Initializes a new instance of the BindingList<T> class with the specified list.

C#
public BindingList(System.Collections.Generic.IList<T> list);

Parameters

list
IList<T>

An IList<T> of items to be contained in the BindingList<T>.

Remarks

Use this BindingList<T> to create a BindingList<T> that is backed by list, which ensures that changes to list are reflected in the BindingList<T>.

The following table shows initial property values for an instance of BindingList<T> class.

Property Initial Value
AllowEdit true
AllowNew true if the list type has a parameterless constructor; otherwise, false.
AllowRemove true
RaiseListChangedEvents true

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1