Właściwość DataRepeater.AllowUserToAddItems —

Pobiera lub ustawia wartość określającą, czy użytkownicy mogą dodawać nowy wiersz do DataRepeater w czasie wykonywania.

Przestrzeń nazw:  Microsoft.VisualBasic.PowerPacks
Zestaw:  Microsoft.VisualBasic.PowerPacks.Vs (w Microsoft.VisualBasic.PowerPacks.Vs.dll)

Składnia

'Deklaracja
Public Property AllowUserToAddItems As Boolean
public bool AllowUserToAddItems { get; set; }
public:
property bool AllowUserToAddItems {
    bool get ();
    void set (bool value);
}
member AllowUserToAddItems : bool with get, set
function get AllowUserToAddItems () : boolean 
function set AllowUserToAddItems (value : boolean)

Wartość właściwości

Typ: Boolean
true Jeśli użytkownik może dodawać wierszy; w przeciwnym razie false.Wartość domyślna to true.

Uwagi

When the AllowUserToAddItems property is set to True, users can add a new row by clicking the BindingNavigatorAddNewItemToolStripButton 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 BindingNavigatorAddNewItemToolStripButton is still enabled.If you want to prevent users from adding rows, you should also disable or remove the BindingNavigatorAddNewItemToolStripButton on the BindingNavigator control.

Przykłady

Poniższy przykładowy kod pokazuje, jak wyłączyć Dodaj przycisk, gdy AllowUserToAddItems ma ustawioną wartość właściwości False.Przyjęto założenie, że formularz, który zawiera DataRepeater formantu o nazwie DataRepeater1 i BindingNavigator formantu o nazwie 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;
    }
}

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

DataRepeater Klasa

Przestrzeń nazw Microsoft.VisualBasic.PowerPacks

Inne zasoby

Wprowadzenie do formantu DataRepeater (Visual Studio)

Porady: wyłączanie dodawania i usuwania elementów DataRepeater (Visual Studio)