DataGridView.RowsRemoved Event
.NET Framework 3.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)
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. This example is part of a larger example available in the SelectionChanged event.
private void DataGridView1_CellValueChanged( object sender, DataGridViewCellEventArgs e) { // Update the balance column whenever the value of any cell changes. UpdateBalance(); } private void DataGridView1_RowsRemoved( object sender, DataGridViewRowsRemovedEventArgs e) { // Update the balance column whenever rows are deleted. UpdateBalance(); } private void UpdateBalance() { int counter; int balance; int deposit; int withdrawal; // Iterate through the rows, skipping the Starting Balance row. for (counter = 1; counter < (DataGridView1.Rows.Count - 1); counter++) { deposit = 0; withdrawal = 0; balance = int.Parse(DataGridView1.Rows[counter - 1] .Cells["Balance"].Value.ToString()); if (DataGridView1.Rows[counter].Cells["Deposits"].Value != null) { // Verify that the cell value is not an empty string. if (DataGridView1.Rows[counter] .Cells["Deposits"].Value.ToString().Length != 0) { deposit = int.Parse(DataGridView1.Rows[counter] .Cells["Deposits"].Value.ToString()); } } if (DataGridView1.Rows[counter].Cells["Withdrawals"].Value != null) { if (DataGridView1.Rows[counter] .Cells["Withdrawals"].Value.ToString().Length != 0) { withdrawal = int.Parse(DataGridView1.Rows[counter] .Cells["Withdrawals"].Value.ToString()); } } DataGridView1.Rows[counter].Cells["Balance"].Value = (balance + deposit + withdrawal).ToString(); } }
Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Community Additions
ADD
Show: