次の方法で共有


DataRow.CancelEdit メソッド

この行の現在の編集をキャンセルします。

Public Sub CancelEdit()
[C#]
public void CancelEdit();
[C++]
public: void CancelEdit();
[JScript]
public function CancelEdit();

例外

例外の種類 条件
InRowChangingEventException RowChanging イベント内でメソッドが呼び出されました。

解説

詳細については、 BeginEdit メソッドのトピックを参照してください。

使用例

[Visual Basic, C#, C++] DataGrid コントロールの最後の行の 1 つの列の値を編集する例を次に示します。この例では、 BeginEdit メソッドと EndEdit メソッドを使用して、列の値を編集し、その変更を行に対してコミットします。

 
Private Sub AcceptOrReject(ByVal myRow As DataRow)
   ' Use a function to validate the row's values.
   ' If the function returns true, end the edit; otherwise cancel it.
   If ValidateRow(myRow) Then
      myRow.EndEdit()
   Else
      myRow.CancelEdit()
   End If
End Sub

Private Function ValidateRow(ByVal myRow As DataRow) As Boolean
   Dim isValid As Boolean
   ' Insert code to validate the row values. Set the isValid variable.
   ValidateRow = isValid
End Function

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

private bool ValidateRow(DataRow thisRow){
   bool isValid = true; 
   // Insert code to validate the row values. Set the isValid variable.
   return isValid;
}

[C++] 
private:
 void AcceptOrReject(DataRow* myRow){
    // Use a function to validate the row's values.
    // If the function returns true, end the edit; otherwise cancel it.
    if(ValidateRow(myRow))
       myRow->EndEdit();
    else
       myRow->CancelEdit();
 }
 
 bool ValidateRow(DataRow* thisRow){
    bool isValid = true; 
    // Insert code to validate the row values. Set the isValid variable.
    return isValid;
 }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

DataRow クラス | DataRow メンバ | System.Data 名前空間 | AcceptChanges | BeginEdit | DataViewRowState | EndEdit | HasVersion | Item | RowState