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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。
請參閱
參考
Microsoft.VisualBasic.PowerPacks 命名空間