Compartir a través de


DataRepeater.AllowUserToAddItemsChanged (Evento)

Se produce cuando cambia la propiedad AllowUserToAddItems.

Espacio de nombres:  Microsoft.VisualBasic.PowerPacks
Ensamblado:  Microsoft.VisualBasic.PowerPacks.Vs (en Microsoft.VisualBasic.PowerPacks.Vs.dll)

Sintaxis

'Declaración
Public Event AllowUserToAddItemsChanged As EventHandler
public event EventHandler AllowUserToAddItemsChanged
public:
 event EventHandler^ AllowUserToAddItemsChanged {
    void add (EventHandler^ value);
    void remove (EventHandler^ value);
}
member AllowUserToAddItemsChanged : IEvent<EventHandler,
    EventArgs>
JScript no admite eventos.

Comentarios

When the AllowUserToAddItems property is set to True, users can add a new row by clicking the BindingNavigatorAddNewItem ToolStripButton on the BindingNavigator control, or by pressing CTRL+N when a DataRepeaterItem has focus.

When the AllowUserToAddItems property is set to False, the CTRL+N keyboard function is disabled, but the BindingNavigatorAddNewItem ToolStripButton is still enabled. If you want to prevent users from adding rows, you should also disable or remove the BindingNavigatorAddNewItem ToolStripButton on the BindingNavigator control.

Para obtener más información acerca de cómo controlar eventos, vea Controlar y provocar eventos.

Ejemplos

En el ejemplo de código siguiente se muestra cómo deshabilitar el agregar botón cuando el AllowUserToAddItems propiedad está establecida en False. Se supone que tiene un formulario que contenga un DataRepeater control denominado DataRepeater1 y un BindingNavigator control denominado ProductsBindingSource.

Private Sub DataRepeater1_AllowUserToAddItemsChanged(
    ) 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;
    }
}

Seguridad de .NET Framework

Vea también

Referencia

DataRepeater Clase

Microsoft.VisualBasic.PowerPacks (Espacio de nombres)

AllowUserToAddItems

AllowUserToDeleteItems

Otros recursos

Introducción al control DataRepeater (Visual Studio)

Cómo: Deshabilitar las operaciones de agregar y eliminar elementos DataRepeater (Visual Studio)