DataGridView.CommitEdit メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As DataGridView Dim context As DataGridViewDataErrorContexts Dim returnValue As Boolean returnValue = instance.CommitEdit(context)
戻り値
変更がコミットされた場合は true。それ以外の場合は false。


このメソッドは、書式設定されたユーザー指定の値を、基になるセル データ型に変換しようとします。これを行うには、CellParsing イベントを発生させます。このイベントを処理すると、型変換をカスタマイズできます。それ以外の場合は、既定の型コンバータが使用されます。DataError イベントが例外を回避するように処理されなかった場合、変換エラーにより例外が発生する可能性があります。値が正常に変換されると、データ ストアにコミットされ、VirtualMode プロパティ値が true の場合、非データ バインド セルに対して CellValuePushed イベントが発生します。値が正常にコミットされると、CellValueChanged イベントが発生します。

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(); } }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridView クラス
DataGridView メンバ
System.Windows.Forms 名前空間
DataGridViewDataErrorContexts
CellParsing
DataError
CellValuePushed
VirtualMode
CellValueChanged
EndEdit
その他の技術情報
DataGridView コントロール (Windows フォーム)
- DataGridView.CommitEdit メソッドのページへのリンク