DataGridView binding problem

  • Thread starter Thread starter B. Chernick
  • Start date Start date
B

B. Chernick

Someone refresh my memory. I have a rather simple Dot Net 2.0 Winforms app
with a DataGridView. The DataGridView is bound to a BindingSource which in
turn is bound to a table.

My problem is this. It appears to me that changes made in fields are not
propagated back to the BindingSource until you leave the current row. What I
would like to do is insure that changes are propagated on CellLeave, whether
or not you leave the row.

Is there any way to trigger this programmatically?
 
Someone refresh my memory. I have a rather simple Dot Net 2.0 Winforms app
with a DataGridView. The DataGridView is bound to a BindingSource which in
turn is bound to a table.

My problem is this. It appears to me that changes made in fields are not
propagated back to the BindingSource until you leave the current row. What I
would like to do is insure that changes are propagated on CellLeave, whether
or not you leave the row.

Is there any way to trigger this programmatically?

I think CommitEdit is what you want.

This is what I do in my subclass of DataGridView to handle this for
checkbox and combobox columns so the change is seen immediately,
before the cell loses focus. I'm sure you could do something similar
in CellLeave.

Protected Overrides Sub OnCurrentCellDirtyStateChanged(ByVal e As
System.EventArgs)
MyBase.OnCurrentCellDirtyStateChanged(e)

If IsCurrentCellDirty Then
If Me.CurrentCell IsNot Nothing AndAlso _
(TypeOf Me.Columns(Me.CurrentCell.ColumnIndex) Is
DataGridViewCheckBoxColumn OrElse _
TypeOf Me.Columns(Me.CurrentCell.ColumnIndex) Is
DataGridViewComboBoxColumn) Then
CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End If

End Sub
 
Sorry but I'm not sure I understand your code. Did you mean something like
this?

Private Sub dgvParts_CellLeave(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvParts.CellLeave
If dgvParts.CurrentCell IsNot Nothing AndAlso
dgvParts.IsCurrentCellDirty Then
dgvParts.CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub

I tried this in both the CellLeave and the CurrentCellDirtyStateChanged
events but it didn't work.
 
No good. It does fire the instant I leave a modified cell (and does the
CommitEdit), but the moment I hit the update button, the old value is
restored.
 
Back
Top