BindingList<T> 建構函式

定義

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

多載

名稱 Description
BindingList<T>()

使用預設值初始化該類別的新實例 BindingList<T>

BindingList<T>(IList<T>)

初始化一個新的類別實例 BindingList<T> ,使用指定的清單。

BindingList<T>()

使用預設值初始化該類別的新實例 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;
void InitializeListOfParts()
{
    // Create the new BindingList of Part type.
    listOfParts = new BindingList<Part>
    {
        // Allow new parts to be added, but not removed once committed.        
        AllowNew = true,
        AllowRemove = false,

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

        // Do not allow parts to be edited.
        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<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

另請參閱

適用於