DataGridViewRowCancelEventArgs 類別
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供 UserDeletingRow 的 DataGridView 事件的資料。
public ref class DataGridViewRowCancelEventArgs : System::ComponentModel::CancelEventArgs
C#
public class DataGridViewRowCancelEventArgs : System.ComponentModel.CancelEventArgs
type DataGridViewRowCancelEventArgs = class
inherit CancelEventArgs
Public Class DataGridViewRowCancelEventArgs
Inherits CancelEventArgs
- 繼承
下列程式碼範例說明此類型的用法。 此範例是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;
}
}
C#
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
。
如需如何處理事件的詳細資訊,請參閱 處理和引發事件。
Cancel |
取得或設定值,這個值表示是否應該取消事件。 (繼承來源 CancelEventArgs) |
Row |
取得使用者要刪除的資料列。 |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
Get |
做為預設雜湊函式。 (繼承來源 Object) |
Get |
取得目前執行個體的 Type。 (繼承來源 Object) |
Memberwise |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
To |
傳回代表目前物件的字串。 (繼承來源 Object) |
產品 | 版本 |
---|---|
.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, 10 |