DataGridViewRowCancelEventArgs 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为 DataGridView 的 UserDeletingRow 事件提供数据。
public ref class DataGridViewRowCancelEventArgs : System::ComponentModel::CancelEventArgs
public class DataGridViewRowCancelEventArgs : System.ComponentModel.CancelEventArgs
type DataGridViewRowCancelEventArgs = class
inherit CancelEventArgs
Public Class DataGridViewRowCancelEventArgs
Inherits CancelEventArgs
- 继承
示例
以下代码示例演示了此类型的用法。 此示例是如何:在 DataGridView 控件中实现虚拟模式 Windows 窗体中提供的更大示例的一部分。
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
注解
若要取消删除事件处理程序中的 UserDeletingRow 行,请将 Cancel 属性设置为 true
。
有关如何处理事件的详细信息,请参阅 处理和引发事件。
构造函数
DataGridViewRowCancelEventArgs(DataGridViewRow) |
初始化 DataGridViewRowCancelEventArgs 类的新实例。 |
属性
Cancel |
获取或设置指示是否应取消事件的值。 (继承自 CancelEventArgs) |
Row |
获取用户要删除的行。 |
方法
Equals(Object) |
确定指定对象是否等于当前对象。 (继承自 Object) |
GetHashCode() |
作为默认哈希函数。 (继承自 Object) |
GetType() |
获取当前实例的 Type。 (继承自 Object) |
MemberwiseClone() |
创建当前 Object 的浅表副本。 (继承自 Object) |
ToString() |
返回表示当前对象的字符串。 (继承自 Object) |