DataGridView.RowsRemoved Event
.NET Framework 2.0
Note: This event is new in the .NET Framework version 2.0.
Occurs when a row or rows are deleted from the DataGridView.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Assembly: System.Windows.Forms (in system.windows.forms.dll)
'Declaration Public Event RowsRemoved As DataGridViewRowsRemovedEventHandler 'Usage Dim instance As DataGridView Dim handler As DataGridViewRowsRemovedEventHandler AddHandler instance.RowsRemoved, handler
/** @event */ public void add_RowsRemoved (DataGridViewRowsRemovedEventHandler value) /** @event */ public void remove_RowsRemoved (DataGridViewRowsRemovedEventHandler value)
JScript supports the use of events, but not the declaration of new ones.
When rows are deleted from a DataGridView control, the index numbers of subsequent rows are lowered to compensate.
For more information about handling events, see Consuming Events.
The following code example demonstrates how to use this event to update the values in a balance column of a DataGridView.
Private Sub CellValueChanged(ByVal sender As Object, _ ByVal e As DataGridViewCellEventArgs) _ Handles DataGridView1.CellValueChanged ' Update the balance column whenever the values of any cell changes. UpdateBalance() End Sub Private Sub RowsRemoved(ByVal sender As Object, _ ByVal e As DataGridViewRowsRemovedEventArgs) _ Handles DataGridView1.RowsRemoved ' Update the balance column whenever rows are deleted. UpdateBalance() End Sub Private Sub UpdateBalance() Dim counter As Integer Dim balance As Integer Dim deposit As Integer Dim withdrawal As Integer ' Iterate through the rows, skipping the Starting Balance Row. For counter = 1 To (DataGridView1.Rows.Count - 2) deposit = 0 withdrawal = 0 balance = Integer.Parse(DataGridView1.Rows(counter - 1) _ .Cells("Balance").Value.ToString()) If Not DataGridView1.Rows(counter) _ .Cells("Deposits").Value Is Nothing Then ' Verify that the cell value is not an empty string. If Not DataGridView1.Rows(counter) _ .Cells("Deposits").Value.ToString().Length = 0 Then deposit = Integer.Parse(DataGridView1.Rows(counter) _ .Cells("Deposits").Value.ToString()) End If End If If Not DataGridView1.Rows(counter) _ .Cells("Withdrawals").Value Is Nothing Then If Not DataGridView1.Rows(counter) _ .Cells("Withdrawals").Value.ToString().Length = 0 Then withdrawal = Integer.Parse(DataGridView1.Rows(counter) _ .Cells("Withdrawals").Value.ToString()) End If End If DataGridView1.Rows(counter).Cells("Balance").Value = _ (balance + deposit + withdrawal).ToString() Next End Sub
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Community Additions
ADD
Show: