DataGridViewRowCancelEventArgs Class
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides data for the UserDeletingRow event of a DataGridView.
public ref class DataGridViewRowCancelEventArgs : System::ComponentModel::CancelEventArgs
public class DataGridViewRowCancelEventArgs : System.ComponentModel.CancelEventArgs
type DataGridViewRowCancelEventArgs = class
inherit CancelEventArgs
Public Class DataGridViewRowCancelEventArgs
Inherits CancelEventArgs
- Inheritance
The following code example illustrates the use of this type. This example is part of a larger example available in How to: Implement Virtual Mode in the Windows Forms DataGridView Control.
void dataGridView1_UserDeletingRow( Object^ /*sender*/,
System::Windows::Forms::DataGridViewRowCancelEventArgs^ e )
{
if ( e->Row->Index < this->customers->Count )
{
// If the user has deleted an existing row, remove the
// corresponding Customer object from the data store.
this->customers->RemoveAt( e->Row->Index );
}
if ( e->Row->Index == this->rowInEdit )
{
// If the user has deleted a newly created row, release
// the corresponding Customer object.
this->rowInEdit = -1;
this->customerInEdit = nullptr;
}
}
private void dataGridView1_UserDeletingRow(object sender,
System.Windows.Forms.DataGridViewRowCancelEventArgs e)
{
if (e.Row.Index < this.customers.Count)
{
// If the user has deleted an existing row, remove the
// corresponding Customer object from the data store.
this.customers.RemoveAt(e.Row.Index);
}
if (e.Row.Index == this.rowInEdit)
{
// If the user has deleted a newly created row, release
// the corresponding Customer object.
this.rowInEdit = -1;
this.customerInEdit = null;
}
}
Private Sub dataGridView1_UserDeletingRow(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) _
Handles dataGridView1.UserDeletingRow
If e.Row.Index < Me.customers.Count Then
' If the user has deleted an existing row, remove the
' corresponding Customer object from the data store.
Me.customers.RemoveAt(e.Row.Index)
End If
If e.Row.Index = Me.rowInEdit Then
' If the user has deleted a newly created row, release
' the corresponding Customer object.
Me.rowInEdit = -1
Me.customerInEdit = Nothing
End If
End Sub
To cancel the deletion of a row in a UserDeletingRow event handler, set the Cancel property to true
.
For more information about how to handle events, see Handling and Raising Events.
Data |
Initializes a new instance of the DataGridViewRowCancelEventArgs class. |
Cancel |
Gets or sets a value indicating whether the event should be canceled. (Inherited from CancelEventArgs) |
Row |
Gets the row that the user is deleting. |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Get |
Serves as the default hash function. (Inherited from Object) |
Get |
Gets the Type of the current instance. (Inherited from Object) |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
To |
Returns a string that represents the current object. (Inherited from Object) |
Product | Versions |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: