DataGridView.CommitEdit メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGridView.CommitEdit メソッドの意味・解説 

DataGridView.CommitEdit メソッド

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

編集モードを終了せずに、現在のセルの変更をデータ キャッシュにコミットします。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Function CommitEdit ( _
    context As DataGridViewDataErrorContexts _
) As Boolean
Dim instance As DataGridView
Dim context As DataGridViewDataErrorContexts
Dim returnValue As Boolean

returnValue = instance.CommitEdit(context)
public bool CommitEdit (
    DataGridViewDataErrorContexts context
)
public:
bool CommitEdit (
    DataGridViewDataErrorContexts context
)
public boolean CommitEdit (
    DataGridViewDataErrorContexts context
)
public function CommitEdit (
    context : DataGridViewDataErrorContexts
) : boolean

パラメータ

context

エラーが発生したコンテキストを指定する DataGridViewDataErrorContexts 値のビットごとの組み合わせ。

戻り値
変更がコミットされた場合は true。それ以外の場合は false。

例外例外
例外の種類条件

Exception

セルの値をコミットできません。DataError イベントのハンドラが存在しないか、ハンドラによって DataGridViewDataErrorEventArgs.ThrowException プロパティが true に設定されました。

解説解説
使用例使用例

CurrentCellDirtyStateChangedイベント ハンドラ内の CommitEdit メソッドを呼び出して、CellValueChanged イベントを発生させるコード例を次に示します。次のコード例は、「方法 : Windows フォーム DataGridView コントロールのボタン列にあるボタンを無効にする」で示されている例の一部です。

' This event handler manually raises the CellValueChanged event
' by calling the CommitEdit method.
Sub dataGridView1_CurrentCellDirtyStateChanged( _
    ByVal sender As Object,
 ByVal e As EventArgs) _
    Handles dataGridView1.CurrentCellDirtyStateChanged

    If dataGridView1.IsCurrentCellDirty Then
        dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
    End If
End Sub

' If a check box cell is clicked, this event handler disables  
' or enables the button in the same row as the clicked cell.
Public Sub dataGridView1_CellValueChanged(ByVal
 sender As Object, _
    ByVal e As DataGridViewCellEventArgs) _
    Handles dataGridView1.CellValueChanged

    If dataGridView1.Columns(e.ColumnIndex).Name = "CheckBoxes"
 Then
        Dim buttonCell As DataGridViewDisableButtonCell
 = _
            CType(dataGridView1.Rows(e.RowIndex).Cells("Buttons"),
 _
            DataGridViewDisableButtonCell)

        Dim checkCell As DataGridViewCheckBoxCell
 = _
            CType(dataGridView1.Rows(e.RowIndex).Cells("CheckBoxes"),
 _
            DataGridViewCheckBoxCell)
        buttonCell.Enabled = Not CType(checkCell.Value, [Boolean])

        dataGridView1.Invalidate()
    End If
End Sub
// This event handler manually raises the CellValueChanged event
// by calling the CommitEdit method.
void dataGridView1_CurrentCellDirtyStateChanged(object sender
,
    EventArgs e)
{
    if (dataGridView1.IsCurrentCellDirty)
    {
        dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
    }
}

// If a check box cell is clicked, this event handler disables  
// or enables the button in the same row as the clicked cell.
public void dataGridView1_CellValueChanged(object
 sender,
    DataGridViewCellEventArgs e)
{
    if (dataGridView1.Columns[e.ColumnIndex].Name == "CheckBoxes")
    {
        DataGridViewDisableButtonCell buttonCell =
            (DataGridViewDisableButtonCell)dataGridView1.
            Rows[e.RowIndex].Cells["Buttons"];

        DataGridViewCheckBoxCell checkCell =
            (DataGridViewCheckBoxCell)dataGridView1.
            Rows[e.RowIndex].Cells["CheckBoxes"];
        buttonCell.Enabled = !(Boolean)checkCell.Value;

        dataGridView1.Invalidate();
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridView クラス
DataGridView メンバ
System.Windows.Forms 名前空間
DataGridViewDataErrorContexts
CellParsing
DataError
CellValuePushed
VirtualMode
CellValueChanged
EndEdit
その他の技術情報
DataGridView コントロール (Windows フォーム)


このページでは「.NET Framework クラス ライブラリ リファレンス」からDataGridView.CommitEdit メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDataGridView.CommitEdit メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDataGridView.CommitEdit メソッド を検索

英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「DataGridView.CommitEdit メソッド」の関連用語

DataGridView.CommitEdit メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataGridView.CommitEdit メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS