Condividi tramite


Proprietà DataRepeater.AllowUserToDeleteItems

Aggiornamento: novembre 2007

Ottiene o imposta un valore che determina se gli utenti possono eliminare una riga da 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 AllowUserToDeleteItems As Boolean

Dim instance As DataRepeater
Dim value As Boolean

value = instance.AllowUserToDeleteItems

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

Valore proprietà

Tipo: System.Boolean

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

Note

Quando la proprietà AllowUserToDeleteItems è impostata su True, gli utenti possono eliminare righe facendo clic su BindingNavigatorDeleteItemToolStripButton nel controllo BindingNavigator oppure premendo CANC quando un oggetto DataRepeaterItem ha lo stato attivo.

Quando la proprietà AllowUserToDeleteItems è impostata su False, la funzione di tastiera CANC è disattivata, ma BindingNavigatorDeleteItemToolStripButton risulta ancora attivato. Se si desidera impedire agli utenti l'eliminazione di righe, è necessario anche disattivare o rimuovere BindingNavigatorDeleteItemToolStripButton nel controllo BindingNavigator.

Esempi

Nell'esempio di codice riportato di seguito viene illustrato come disattivare il pulsante Delete ToolStripButton 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.

Private Sub DataRepeater1_AllowUserToDeleteItemsChanged _
 (ByVal sender As Object, ByVal e As System.EventArgs) Handles _
  DataRepeater1.AllowUserToDeleteItemsChanged
    ' If this event occurs during form initialization, exit.
    If Me.IsHandleCreated = False Then Exit Sub
    ' If AllowUserToDeleteItems is False.
    If DataRepeater1.AllowUserToDeleteItems = False Then
        ' Disable the Delete button.
        BindingNavigatorDeleteItem.Enabled = False
    Else
        ' Otherwise, enable the Delete button.
        BindingNavigatorDeleteItem.Enabled = True
    End If
End Sub
Private Sub BindingNavigatorDeleteItem_EnabledChanged(ByVal sender _
 As Object, ByVal e As System.EventArgs) Handles _
 BindingNavigatorDeleteItem.EnabledChanged
    If DataRepeater1.AllowUserToDeleteItems = False Then
        ' The BindingSource resets this property when a 
        ' new record is selected, so override it.
        If BindingNavigatorDeleteItem.Enabled = True Then
            BindingNavigatorDeleteItem.Enabled = False
        End If
    End If
End Sub
private void dataRepeater1_AllowUserToDeleteItemsChanged(object sender, System.EventArgs e)
{
    // If this event occurs during form initialization, exit.
    if (this.IsHandleCreated == false) { return; }
    // If AllowUserToDeleteItems is False.
    if (dataRepeater1.AllowUserToDeleteItems == false)
    // Disable the Delete button.
    {
        bindingNavigatorDeleteItem.Enabled = false;
    }
    else
    {
        // Otherwise, enable the Delete button.
        bindingNavigatorDeleteItem.Enabled = true;
    }
}
private void bindingNavigatorDeleteItem_EnabledChanged(object sender, System.EventArgs e)
{
    if (dataRepeater1.AllowUserToDeleteItems == false)
    // The BindingSource resets this property when a 
    // new record is selected, so override it.
    {
        if (bindingNavigatorDeleteItem.Enabled == true)
        {
            bindingNavigatorDeleteItem.Enabled = false;
        }
    }
}

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)