DataRepeater.AllowUserToAddItemsChanged Event

 

Occurs when the AllowUserToAddItems property changes.

Namespace:   Microsoft.VisualBasic.PowerPacks
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)

Syntax

public event EventHandler AllowUserToAddItemsChanged
public:
event EventHandler^ AllowUserToAddItemsChanged {
    void add(EventHandler^ value);
    void remove(EventHandler^ value);
}
member AllowUserToAddItemsChanged : IEvent<EventHandler,
    EventArgs>
Public Event AllowUserToAddItemsChanged As EventHandler

Remarks

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.

For more information about how to handle events, see Handling and Raising Events.

Examples

The following code example demonstrates how to disable the Add button when the AllowUserToAddItems property is set to False. It assumes that you have a form that contains a DataRepeater control named DataRepeater1 and a BindingNavigator control named ProductsBindingSource.

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;
    }
}
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

See Also

AllowUserToAddItems
AllowUserToDeleteItems
DataRepeater Class
Microsoft.VisualBasic.PowerPacks Namespace
Introduction to the DataRepeater Control (Visual Studio)
How to: Disable Adding and Deleting DataRepeater Items (Visual Studio)

Return to top