共用方式為


DataRepeater.AllowUserToDeleteItems 屬性

取得或設定值,這個值會決定使用者是否可以刪除的資料列DataRepeater在執行階段。

命名空間:  Microsoft.VisualBasic.PowerPacks
組件:  Microsoft.VisualBasic.PowerPacks.Vs (在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)

語法

'宣告
Public Property AllowUserToDeleteItems As Boolean
public bool AllowUserToDeleteItems { get; set; }
public:
property bool AllowUserToDeleteItems {
    bool get ();
    void set (bool value);
}
member AllowUserToDeleteItems : bool with get, set
function get AllowUserToDeleteItems () : boolean 
function set AllowUserToDeleteItems (value : boolean)

屬性值

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

備註

When the AllowUserToDeleteItems property is set to True, users can delete rows by clicking the BindingNavigatorDeleteItem ToolStripButton on the BindingNavigator control, or by pressing DELETE when a DataRepeaterItem has focus.

When the AllowUserToDeleteItems property is set to False, the DELETE keyboard function is disabled, but the BindingNavigatorDeleteItem ToolStripButton is still enabled. If you want to prevent users from deleting rows, you should also disable or remove the BindingNavigatorDeleteItem ToolStripButton on the BindingNavigator control.

範例

下列程式碼範例示範如何停用刪除ToolStripButton按鈕時AllowUserToAddItems屬性設定為False。 這裡假設您有包含表單的DataRepeater名為控制項DataRepeater1和BindingNavigator控制項。

Private Sub DataRepeater1_AllowUserToDeleteItemsChanged(
    ) Handles DataRepeater1.AllowUserToDeleteItemsChanged

    ' If this event occurs during form initialization, exit. 
    If Me.IsHandleCreated = False Then Exit Sub 
    ' If AllowUserToDeleteItems is False. 
    If DataRepeater1.AllowUserToDeleteItems = False Then 
        ' Disable the Delete button.
        BindingNavigatorDeleteItem.Enabled = False 
    Else 
        ' Otherwise, enable the Delete button.
        BindingNavigatorDeleteItem.Enabled = True 
    End If 
End Sub 
Private Sub BindingNavigatorDeleteItem_EnabledChanged(
    ) Handles BindingNavigatorDeleteItem.EnabledChanged

    If DataRepeater1.AllowUserToDeleteItems = False Then 
        ' The BindingSource resets this property when a  
        ' new record is selected, so override it. 
        If BindingNavigatorDeleteItem.Enabled = True Then
            BindingNavigatorDeleteItem.Enabled = False 
        End If 
    End If 
End Sub
private void dataRepeater1_AllowUserToDeleteItemsChanged(object sender, System.EventArgs e)
{
    // If this event occurs during form initialization, exit. 
    if (this.IsHandleCreated == false) { return; }
    // If AllowUserToDeleteItems is False. 
    if (dataRepeater1.AllowUserToDeleteItems == false)
    // Disable the Delete button.
    {
        bindingNavigatorDeleteItem.Enabled = false;
    }
    else
    {
        // Otherwise, enable the Delete button.
        bindingNavigatorDeleteItem.Enabled = true;
    }
}
private void bindingNavigatorDeleteItem_EnabledChanged(object sender, System.EventArgs e)
{
    if (dataRepeater1.AllowUserToDeleteItems == false)
    // The BindingSource resets this property when a  
    // new record is selected, so override it.
    {
        if (bindingNavigatorDeleteItem.Enabled == true)
        {
            bindingNavigatorDeleteItem.Enabled = false;
        }
    }
}

.NET Framework 安全性

請參閱

參考

DataRepeater 類別

Microsoft.VisualBasic.PowerPacks 命名空間

其他資源

DataRepeater 控制項簡介 (Visual Studio)

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