Właściwość DataRepeater.AllowUserToDeleteItems —
Pobiera lub ustawia wartość określającą, czy użytkownicy mogą usuwać wiersz z DataRepeater w czasie wykonywania.
Przestrzeń nazw: Microsoft.VisualBasic.PowerPacks
Zestaw: Microsoft.VisualBasic.PowerPacks.Vs (w Microsoft.VisualBasic.PowerPacks.Vs.dll)
Składnia
'Deklaracja
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)
Wartość właściwości
Typ: Boolean
true Jeśli użytkownik może usuwać wierszy; w przeciwnym razie false.Wartość domyślna to true.
Uwagi
When the AllowUserToDeleteItems property is set to True, users can delete rows by clicking the BindingNavigatorDeleteItemToolStripButton 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 BindingNavigatorDeleteItemToolStripButton is still enabled.If you want to prevent users from deleting rows, you should also disable or remove the BindingNavigatorDeleteItemToolStripButton on the BindingNavigator control.
Przykłady
Poniższy przykładowy kod pokazuje, jak wyłączyć Delete ToolStripButton przycisk, gdy AllowUserToAddItems ma ustawioną wartość właściwości False.Przyjęto założenie, że formularz, który zawiera DataRepeater formantu o nazwie DataRepeater1 i BindingNavigator kontroli.
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;
}
}
}
Zabezpieczenia programu .NET Framework
- Pełne zaufanie do bezpośredniego wywołującego. Tego elementu członkowskiego nie można używać w kodzie częściowo zaufanym. Aby uzyskać więcej informacji, zobacz Używanie bibliotek pochodzących z częściowo zaufanego kodu.
Zobacz też
Informacje
Przestrzeń nazw Microsoft.VisualBasic.PowerPacks
Inne zasoby
Wprowadzenie do formantu DataRepeater (Visual Studio)
Porady: wyłączanie dodawania i usuwania elementów DataRepeater (Visual Studio)