DataRowView.CancelEdit 方法

定义

取消编辑过程。

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

实现

示例

以下示例编辑 中的行 DataViewCancelEdit调用 方法以在验证失败时取消更改。

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后,将回滚对行所做的所有更改。 还可以通过调用 RejectChangesDataTable级 来回滚更改。

适用于

另请参阅