BindingList<T>.AllowNew Propriedade

Definição

Obtém ou define um valor que indica se é possível adicionar itens à lista usando o método 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

Valor da propriedade

true se for possível adicionar itens à lista com o método AddNew(); caso contrário, false. O padrão depende do tipo subjacente contido na lista.

Exemplos

O exemplo de código a seguir demonstra como definir a AllowNew propriedade . Para obter o exemplo completo, consulte o tópico de visão geral da 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

Comentários

Normalmente AllowNew , a propriedade é usada por outros componentes para determinar se a criação de novos itens é permitida. AllowNew o padrão será se o tipo contido na lista tiver um construtor sem parâmetros true ou o AddingNew evento for tratado. Se o AddingNew evento não for tratado ou o tipo de lista não tiver um construtor sem parâmetrosfalse, o AllowNew padrão será .

Se AllowNew for definido explicitamente, o valor definido sempre será usado por objetos associados para determinar se novos itens podem ser adicionados à lista. Seja AllowNew ou truefalse, novos itens podem ser adicionados chamando AddNew explicitamente se o tipo de lista tiver um construtor sem parâmetros ou o AddingNew evento for tratado. Além disso, a configuração AllowNew faz com que um ListChanged evento do tipo Reset ocorra.

Aplica-se a

Confira também