I have a form with a bound datagrid. When I close the form, I update the
datasource with the changes made in the grid. However, I close the form, the
most recent changes made to the grid are not updated. How do I force the
grid/datasource to save the most recent changes before the form is closed?
Thanks
I'm struggling with this same problem.
The issue is that the grid changes are not committed to the underlying data
source until the edited row is moved from in the grid.
The standard reply is to use the end edit methods of the currency manager:
Dim cm As CurrencyManager =
CType(ogrid.BindingContext(ogrid.DataSource, ogrid.DataMember),
CurrencyManager)
cm.EndCurrentEdit()
or the datarowview:
Dim dvw As DataView = CType(ogrid.DataSource, DataTable).DefaultView
dvw.Item(ogrid.CurrentCell.RowNumber).EndEdit()
But it seems to me (anybody who can confirm or deny, let me know) that this
only works if you move from the edited *column*, though you need not move
from the row.
What I am using (today at least) is the datagrid.EndEdit method.
This requirs you to access the grid table styles, which I am not sure is
available for default grid binding unless you set it up by hand.
So I put this code in the grid Leave event.
Dim dgc As DataGridColumnStyle
If ogrid.CurrentCell.RowNumber >= 0 Then
dgc =
ogrid.TableStyles(0).GridColumnStyles(ogrid.CurrentCell.ColumnNumber)
ogrid.EndEdit(dgc, ogrid.CurrentCell.RowNumber, False)
End If
and whatnot.
It seems that a large amount of people using the datagrid control encounter
this problem. Maybe MS can look at this and make the grid's behaviour a
little more intuitive in future releases.
Oh, and that reminds me; Happy Birthday to Bill G.! (Gather those rosebuds)
> I have a form with a bound datagrid. When I close the form, I update the
> datasource with the changes made in the grid. However, I close the form, the
> most recent changes made to the grid are not updated. How do I force the
> grid/datasource to save the most recent changes before the form is closed?
>
> Thanks
Jonathan Steinberg
BR Corp
jsteinberg@NOTBrcorp.com
Milko - 27 Apr 2005 23:59 GMT
Hello JS,
I have similar problem with the data edited in data grid.
The grid Leave event occurs when we change the focus to different control(
let say edit box). The problem is that if we click a menu object or panel for
example, then there is no grid Leave event, yet. So, the expected grid Leave
event can arrive much later than necessary (when we click on another control
that takes the focus).
Have you found some solution in this aspect?
Best Regards,
Milko
> I'm struggling with this same problem.
> The issue is that the grid changes are not committed to the underlying data
[quoted text clipped - 45 lines]
> BR Corp
> jsteinberg@NOTBrcorp.com