共用方式為


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)

屬性值

類型:Boolean
true如果使用者可以加入資料列。否則false。預設為 true。

備註

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.

範例

下列程式碼範例示範如何停用 [新增] 按鈕時AllowUserToAddItems屬性設定為False。 這裡假設您有包含表單的DataRepeater名為控制項DataRepeater1和BindingNavigator名為控制項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;
    }
}

.NET Framework 安全性

請參閱

參考

DataRepeater 類別

Microsoft.VisualBasic.PowerPacks 命名空間

其他資源

DataRepeater 控制項簡介 (Visual Studio)

如何:停用加入和刪除 DataRepeater 項目 (Visual Studio)