BindingList<T>.AllowNew Proprietà

Definizione

Ottiene o imposta un valore che indica se è possibile aggiungere elementi all'elenco utilizzando il metodo AddNew().

public:
 property bool AllowNew { bool get(); void set(bool value); };
public bool AllowNew { get; set; }
member this.AllowNew : bool with get, set
Public Property AllowNew As Boolean

Valore della proprietà

true se è possibile aggiungere elementi all'elenco con il metodo AddNew(); in caso contrario, false. L'impostazione predefinita dipende dal tipo sottostante contenuto nell'elenco.

Esempio

Nell'esempio di codice seguente viene illustrato come impostare la AllowNew proprietà. Per l'esempio completo, vedere l'argomento panoramica della BindingList<T> classe.

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

Commenti

La AllowNew proprietà viene in genere usata da altri componenti per determinare se è consentita la creazione di nuovi elementi. AllowNew per impostazione predefinita se true il tipo contenuto nell'elenco ha un costruttore senza parametri o l'evento AddingNew viene gestito. Se l'evento AddingNew non viene gestito o il tipo di elenco non dispone di un costruttore senza parametri, AllowNew il valore predefinito è false.

Se AllowNew è impostato in modo esplicito, il valore impostato verrà sempre usato dagli oggetti associati per determinare se è possibile aggiungere nuovi elementi all'elenco. Se AllowNew è true o false, è possibile aggiungere nuovi elementi chiamando AddNew in modo esplicito se il tipo di elenco ha un costruttore senza parametri o l'evento AddingNew viene gestito. Inoltre, l'impostazione causa l'esecuzione AllowNew di un ListChanged evento di tipo Reset .

Si applica a

Vedi anche