PC Review


Reply
Thread Tools Rate Thread

DataGridView binding problem

 
 
B. Chernick
Guest
Posts: n/a
 
      29th Oct 2008
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?
 
Reply With Quote
 
 
 
 
Jack Jackson
Guest
Posts: n/a
 
      29th Oct 2008
On Wed, 29 Oct 2008 11:36:05 -0700, B. Chernick
<(E-Mail Removed)> wrote:

>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
 
Reply With Quote
 
BC
Guest
Posts: n/a
 
      30th Oct 2008
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.

"Jack Jackson" wrote:

> On Wed, 29 Oct 2008 11:36:05 -0700, B. Chernick
> <(E-Mail Removed)> wrote:
>
> >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
>

 
Reply With Quote
 
Jack Jackson
Guest
Posts: n/a
 
      30th Oct 2008
Yes, that is what I meant. What happens if you set a breakpoint in
the code?


On Wed, 29 Oct 2008 17:40:00 -0700, BC <(E-Mail Removed)>
wrote:

>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.
>
>"Jack Jackson" wrote:
>
>> On Wed, 29 Oct 2008 11:36:05 -0700, B. Chernick
>> <(E-Mail Removed)> wrote:
>>
>> >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
>>

 
Reply With Quote
 
BC
Guest
Posts: n/a
 
      30th Oct 2008
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.

"Jack Jackson" wrote:

> Yes, that is what I meant. What happens if you set a breakpoint in
> the code?
>
>
> On Wed, 29 Oct 2008 17:40:00 -0700, BC <(E-Mail Removed)>
> wrote:
>
> >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.
> >
> >"Jack Jackson" wrote:
> >
> >> On Wed, 29 Oct 2008 11:36:05 -0700, B. Chernick
> >> <(E-Mail Removed)> wrote:
> >>
> >> >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
> >>

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGridView binding problem/theory question BC Microsoft ADO .NET 0 30th Oct 2008 08:26 PM
Binding List<T> to a DataGridView = DataGridView Empty admlangford@gmail.com Microsoft C# .NET 3 1st Oct 2008 07:59 AM
DataView to DataGridView binding problem =?Utf-8?B?RXZl?= Microsoft Dot NET Framework Forms 2 13th Nov 2006 08:13 PM
DataGridView binding problem with custom collection =?Utf-8?B?U3R1YXJ0?= Microsoft Dot NET 4 23rd Jul 2006 11:54 PM
DataGridView binding problem =?Utf-8?B?TGFycnkgQ2hhcmx0b24=?= Microsoft Dot NET Framework Forms 1 14th May 2006 05:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:45 AM.