次の方法で共有


DataRow.EndEdit メソッド

この行で行われている編集を終了します。

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

例外

例外の種類 条件
InRowChangingEventException RowChanging イベント内でメソッドが呼び出されました。
ConstraintException 編集が制約に違反しています。
ReadOnlyException この行がこのテーブルに属し、編集によって読み取り専用の列の値を変更しようとしています。
NoNullAllowedException 編集によって、 AllowDBNull が false である列に null 値を挿入しようとしています。

解説

このプロパティを設定すると、 RowChanging イベントで例外が発生した場合に例外が生成されます。

使用例

[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 | AllowDBNull | BeginEdit | CancelEdit | HasVersion | Item | RowState