DataRow.CancelEdit 方法

定義

取消資料列上目前的編輯。

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

例外狀況

RowChanging 事件中呼叫該方法。

範例

下列範例會編輯 控件最後一個數據列中一個 DataGrid 數據行的值。 此範例會 BeginEdit使用、 EndEdit方法來編輯數據行的值,並將變更認可至數據列。

private void AcceptOrReject(DataRow row)
{
    // Use a function to validate the row's values.
    // If the function returns true, end the edit;
    // otherwise cancel it.
    if(ValidateRow(row))
        row.EndEdit();
    else
        row.CancelEdit();
}

private bool ValidateRow(DataRow thisRow)
{
    bool isValid = true;
    // Insert code to validate the row values.
    // Set the isValid variable.
    return isValid;
}
 Private Sub AcceptOrReject(ByVal row As DataRow)
    ' Use a function to validate the row's values.
    ' If the function returns true, end the edit; 
    ' otherwise cancel it.
    If ValidateRow(row) Then
       row.EndEdit()
    Else
       row.CancelEdit()
    End If
End Sub
 
Private Function ValidateRow(ByVal row As DataRow) As Boolean
    Dim isValid As Boolean
    ' Insert code to validate the row values. 
    ' Set the isValid variable.
    ValidateRow = isValid
End Function

備註

如需詳細資訊,請參閱 BeginEdit 方法。

適用於

另請參閱