DataRepeater.AllowUserToAddItems 属性

获取或设置该值来确定用户是否可以添加新行。 DataRepeater 在运行时。

命名空间:  Microsoft.VisualBasic.PowerPacks
程序集:  Microsoft.VisualBasic.PowerPacks.Vs(在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)

语法

声明
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)

属性值

类型:System.Boolean
true ,如果用户可以将行;否则 false。默认值为 true。

备注

当 AllowUserToAddItems 属性设置为 True时,用户可以添加新行通过单击 BindingNavigatorAddNewItemToolStripButtonBindingNavigator 控件,或者按 CTRL+N,当 DataRepeaterItem 具有焦点时。

当 AllowUserToAddItems 属性设置为 False时, CTRL+N 键盘函数禁用,但是, BindingNavigatorAddNewItemToolStripButton 仍处于启用状态。如果要防止用户添加行,还应禁用或移除在 BindingNavigator 控件的 BindingNavigatorAddNewItemToolStripButton

示例

,当 AllowUserToAddItems 属性设置为 False时,下面的代码示例演示如何禁止添加按钮。它,假设您具有包含一个 DataRepeater 控件 DataRepeater1 的、名为 ProductsBindingSource的一个 BindingNavigator 控件的窗体。

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

.NET Framework 安全性

请参见

参考

DataRepeater 类

Microsoft.VisualBasic.PowerPacks 命名空间

其他资源

DataRepeater 控件简介 (Visual Studio)

如何:禁止添加和删除 DataRepeater 项 (Visual Studio)