Bewerken

Delen via


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.

public:
 BindingList();
public BindingList ();
Public Sub New ()

Examples

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

    // 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));
    }
' Declare a new BindingListOfT with the Part business object.
Private WithEvents listOfParts As BindingList(Of Part)

Private Sub InitializeListOfParts()

    ' Create the new BindingList of Part type.
    listOfParts = New BindingList(Of 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))

End Sub

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

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.

public:
 BindingList(System::Collections::Generic::IList<T> ^ list);
public BindingList (System.Collections.Generic.IList<T> list);
new System.ComponentModel.BindingList<'T> : System.Collections.Generic.IList<'T> -> System.ComponentModel.BindingList<'T>
Public Sub New (list As IList(Of T))

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