BindingList<T> 建構函式

定義

初始化 BindingList<T> 類別的新執行個體。

多載

BindingList<T>()

使用預設值,初始化 BindingList<T> 類別的新執行個體。

BindingList<T>(IList<T>)

初始化具有指定的清單之 BindingList<T> 類別的新執行個體。

BindingList<T>()

來源:
BindingList.cs
來源:
BindingList.cs
來源:
BindingList.cs

使用預設值,初始化 BindingList<T> 類別的新執行個體。

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

範例

下列程式代碼範例示範如何建構新的 BindingList<T>。 如需完整的範例,請參閱 BindingList<T> 類別概觀主題。

    // 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

備註

下表顯示 BindingList<T> 類別執行個體的初始屬性值。

屬性 初始值
AllowEdit true
AllowNew true 如果清單類型具有無參數建構函式,則為 ;否則為 false
AllowRemove true
RaiseListChangedEvents true

另請參閱

適用於

BindingList<T>(IList<T>)

來源:
BindingList.cs
來源:
BindingList.cs
來源:
BindingList.cs

初始化具有指定的清單之 BindingList<T> 類別的新執行個體。

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))

參數

list
IList<T>

IList<T> 中所要包含之項目的 BindingList<T>

備註

BindingList<T>使用此方法來建立 BindingList<T>list支援的 ,以確保的變更list會反映在 中BindingList<T>

下表顯示 BindingList<T> 類別執行個體的初始屬性值。

屬性 初始值
AllowEdit true
AllowNew true 如果清單類型具有無參數建構函式,則為 ;否則為 false
AllowRemove true
RaiseListChangedEvents true

另請參閱

適用於