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 控制項上按一下 BindingNavigatorAddNewItemToolStripButton,二是在 DataRepeaterItem 獲得焦點 (Focus) 時按 CTRL+N。

當 AllowUserToAddItems 屬性是設定為 False 時,會停用 CTRL+N 鍵盤功能,但 BindingNavigatorAddNewItemToolStripButton 仍然處於啟用狀態。如果您想要讓使用者無法加入資料列,應該也要在 BindingNavigator 控制項上停用或移除 BindingNavigatorAddNewItemToolStripButton

範例

在下列程式碼範例中,會示範當 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)

HOW TO:停用加入和刪除 DataRepeater 項目 (Visual Studio)