Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / April 2005

Tip: Looking for answers? Try searching our database.

saving rows in a Datagrid

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Todd McCarty - 27 Oct 2004 22:15 GMT
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
JS - 28 Oct 2004 19:09 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.