DataRepeater.AllowUserToAddItems 属性

更新:2007 年 11 月

获取或设置一个值,该值决定在运行时用户是否可以向 DataRepeater 添加新行。

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

语法

声明
Public Property AllowUserToAddItems As Boolean
用法
Dim instance As DataRepeater
Dim value As Boolean

value = instance.AllowUserToAddItems

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

属性值

类型:System.Boolean

如果用户可以添加行,则为 true;否则为 false。其默认值为 true。

备注

当 AllowUserToAddItems 属性设置为 True 时,用户可以通过单击 BindingNavigator 控件上的“BindingNavigatorAddNewItem”ToolStripButton 来添加新行,或者在 DataRepeaterItem 具有焦点时通过按 Ctrl+N 来添加新行。

当 AllowUserToAddItems 属性设置为 False 时,Ctrl+N 键盘功能将被禁用,但“BindingNavigatorAddNewItem”ToolStripButton 仍然可用。 如果要防止用户添加行,您还应该禁用或移除 BindingNavigator 控件上的“BindingNavigatorAddNewItem”ToolStripButton

示例

下面的代码示例演示当 AllowUserToAddItems 属性设置为 False 时如何禁用“Add”(添加)按钮。 假定您有一个窗体,其中包含一个名为 DataRepeater1 的 DataRepeater 控件和一个名为 ProductsBindingSource 的 BindingNavigator 控件。

Private Sub DataRepeater1_AllowUserToAddItemsChanged(ByVal sender _
 As Object, ByVal e As System.EventArgs) 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;
    }
}

权限

另请参见

参考

DataRepeater 类

DataRepeater 成员

Microsoft.VisualBasic.PowerPacks 命名空间

其他资源

DataRepeater 控件简介 (Visual Studio)

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