DataGridView.UserDeletingRow Händelse
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Inträffar när användaren tar bort en rad från DataGridView kontrollen.
public:
event System::Windows::Forms::DataGridViewRowCancelEventHandler ^ UserDeletingRow;
public event System.Windows.Forms.DataGridViewRowCancelEventHandler UserDeletingRow;
public event System.Windows.Forms.DataGridViewRowCancelEventHandler? UserDeletingRow;
member this.UserDeletingRow : System.Windows.Forms.DataGridViewRowCancelEventHandler
Public Custom Event UserDeletingRow As DataGridViewRowCancelEventHandler
Händelsetyp
Exempel
I följande kodexempel visas hur du använder UserDeletingRow händelsen för att avbryta borttagningen av rader från DataGridView raden om startbalans ingår i markeringen. Det här exemplet är en del av ett större exempel som är tillgängligt i händelsen SelectionChanged .
private void DataGridView1_UserDeletingRow(object sender,
DataGridViewRowCancelEventArgs e)
{
DataGridViewRow startingBalanceRow = DataGridView1.Rows[0];
// Check if the Starting Balance row is included in the selected rows
if (DataGridView1.SelectedRows.Contains(startingBalanceRow))
{
// Do not allow the user to delete the Starting Balance row.
MessageBox.Show("Cannot delete Starting Balance row!");
// Cancel the deletion if the Starting Balance row is included.
e.Cancel = true;
}
}
Private Sub UserDeletingRow(ByVal sender As Object, _
ByVal e As DataGridViewRowCancelEventArgs) _
Handles DataGridView1.UserDeletingRow
Dim startingBalanceRow As DataGridViewRow = DataGridView1.Rows(0)
' Check if the starting balance row is included in the selected rows
If DataGridView1.SelectedRows.Contains(startingBalanceRow) Then
' Do not allow the user to delete the Starting Balance row.
MessageBox.Show("Cannot delete Starting Balance row!")
' Cancel the deletion if the Starting Balance row is included.
e.Cancel = True
End If
End Sub
Kommentarer
Den här händelsen kan avbrytas för att förhindra att en radborttagning slutförs.
Mer information om hur du hanterar händelser finns i Hantera och höja händelser.