DataRowView.CancelEdit 方法

定义

取消编辑过程。Cancels an edit procedure.

public:
 virtual void CancelEdit();
public void CancelEdit ();
abstract member CancelEdit : unit -> unit
override this.CancelEdit : unit -> unit
Public Sub CancelEdit ()

实现

示例

下面的示例在 DataView 中编辑行。The following example edits a row in a DataView. 如果验证失败,则调用 CancelEdit 方法取消更改。The CancelEdit method is called to cancel the changes if the validation fails.

   private void EditDataRowView(DataRowView rowView, 
       string columnToEdit) 
   {
       rowView.BeginEdit();
       rowView[columnToEdit] = textBox1.Text;

       // Validate the input with a function.
       if (ValidateCompanyName(rowView[columnToEdit]))
           rowView.EndEdit();   
       else
           rowView.CancelEdit();
   }

   private bool ValidateCompanyName(object valuetoCheck) 
   {
       // Insert code to validate the value.
       return true;
   }
Private Sub EditDataRowView(rowView As DataRowView, _
    columnToEdit As String)
    rowView.BeginEdit()
    rowView(columnToEdit) = textBox1.Text

    ' Validate the input with a function.
    If ValidateCompanyName(rowView(columnToEdit)) Then
        rowView.EndEdit()
    Else
        rowView.CancelEdit()
    End If
End Sub
     
Private Function ValidateCompanyName( _
    valuetoCheck As Object) As Boolean
    ' Insert code to validate the value.
    Return True
End Function

注解

调用 CancelEdit 后,对该行进行的所有更改都将回滚。After calling CancelEdit, all changes to the row are rolled back. 还可以通过在父级 DataTable 上调用 RejectChanges 来回滚更改。You can also roll back changes by calling RejectChanges on the parent DataTable.

适用于

另请参阅