Condividi tramite


Proprietà DataRepeater.AllowUserToAddItems

Aggiornamento: novembre 2007

Ottiene o imposta un valore che determina se gli utenti possono aggiungere una nuova riga a un oggetto DataRepeater in fase di esecuzione.

Spazio dei nomi:  Microsoft.VisualBasic.PowerPacks
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)

Sintassi

Public Property AllowUserToAddItems As Boolean

Dim instance As DataRepeater
Dim value As Boolean

value = instance.AllowUserToAddItems

instance.AllowUserToAddItems = value
public bool AllowUserToAddItems { get; set; }
public:
property bool AllowUserToAddItems {
    bool get ();
    void set (bool value);
}
public function get AllowUserToAddItems () : boolean
public function set AllowUserToAddItems (value : boolean)

Valore proprietà

Tipo: System.Boolean

true se l'utente può aggiungere righe; in caso contrario, false. Il valore predefinito è true.

Note

Quando la proprietà AllowUserToAddItems è impostata su True, gli utenti possono aggiungere una nuova riga facendo clic su BindingNavigatorAddNewItemToolStripButton nel controllo BindingNavigator oppure premendo CTRL+N quando un oggetto DataRepeaterItem ha lo stato attivo.

Quando la proprietà AllowUserToAddItems è impostata su False, la funzione di tastiera CTRL+N è disattivata, ma BindingNavigatorAddNewItemToolStripButton risulta ancora attivato. Se si desidera impedire agli utenti l'aggiunta di righe, è necessario anche disattivare o rimuovere BindingNavigatorAddNewItemToolStripButton nel controllo BindingNavigator.

Esempi

Nell'esempio di codice riportato di seguito viene illustrato come disattivare il pulsante Add quando la proprietà AllowUserToAddItems è impostata su False. Nell'esempio si suppone di disporre di un form che contiene un controllo DataRepeater denominato DataRepeater1 e un controllo BindingNavigator denominato ProductsBindingSource.

Private Sub DataRepeater1_AllowUserToAddItemsChanged(ByVal sender _
 As Object, ByVal e As System.EventArgs) Handles _
 DataRepeater1.AllowUserToAddItemsChanged
    ' If this event occurs during form initialization, exit.
    If Me.IsHandleCreated = False Then Exit Sub
    ' If AllowUserToAddItems is False.
    If DataRepeater1.AllowUserToAddItems = False Then
        ' Disable the Add button.
        BindingNavigatorAddNewItem.Enabled = False
        ' Disable the BindingSource property.
        ProductsBindingSource.AllowNew = False
    Else
        ' Otherwise, enable the Add button.
        BindingNavigatorAddNewItem.Enabled = True
    End If
End Sub
private void dataRepeater1_AllowUserToAddItemsChanged(object sender, System.EventArgs e)
{
    // If this event occurs during form initialization, exit.
    if (this.IsHandleCreated == false) { return; }
    // If AllowUserToAddItems is False.
    if (dataRepeater1.AllowUserToAddItems == false)
    // Disable the Add button.
    {
        bindingNavigatorAddNewItem.Enabled = false;
        // Disable the BindingSource property.
        productsBindingSource.AllowNew = false;
    }
    else
    {
        // Otherwise, enable the Add button.
        bindingNavigatorAddNewItem.Enabled = true;
    }
}

Autorizzazioni

Vedere anche

Riferimenti

DataRepeater Classe

Membri DataRepeater

Spazio dei nomi Microsoft.VisualBasic.PowerPacks

Altre risorse

Introduzione al controllo DataRepeater (Visual Studio)

Procedura: disattivare l'aggiunta e l'eliminazione di elementi DataRepeater (Visual Studio)