|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Updating a DataSet while using DataGridViewCan anyone tell me the best way to update a dataset while it is being
edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should you update after closing the grid/form, etc.? Also, can you tell me the best book to buy that fully explains the DataGridView control? Thanks. Interesting that not a lot of people are using the datagridview object yet.
Anyway, here is what I do. In my example (from an app I am currently working on) I add data to the new row to the datagridview. The trick is to add the row to the underlying dataTable which is the datasource of the datagridview: Private Sub dgrModSubDetail_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgrModSubDetail.CellEndEdit Dim dr As DataRow If e.RowIndex > dsWeb.Tables("modSubDetail").Rows.Count - 1 Then dr = dsWeb.Tables("modSubDetail").NewRow dsWeb.Tables("modSubDetail").Rows.Add(dr) dsWeb.Tables("modSubDetail").AcceptChanges() End If End Sub e is the datagridview cell event arg for the CellEndEdit event of the datagridview. I have observed that the CellEndEdit event is the last event to fire when you leave a datagridview. e returns the row index (and also column index). If the row index is greater than the number of rows in the underlying datatable, I add a new datarow to the underlying datatable. You can edit the datarow directly from/through the datagridview. This is very convenient because you don't have to do the dr.Item(0) = ... like in vb2003. Once you get the hang of the datagridview - it is real nice. Note: I am open to suggestions here if my method is on the kludgy side. Rich Show quoteHide quote "b**@datasync.com" wrote: > Can anyone tell me the best way to update a dataset while it is being > edited/viewed in the DataGridView control? Is this something that > should be inserted into one of the grid's events? or should you update > after closing the grid/form, etc.? > > Also, can you tell me the best book to buy that fully explains the > DataGridView control? > > Thanks. > > Rich,
Thanks for your input. I'm still so new at this that I'm just feeling my way. I've got the datagridview working pretty well in the first draft of my program, and I'm not using AcceptChanges at all. I just use the Update method of the dataAdapter when I'm done. I've got a lot to learn I know, but I have heard that AcceptChanges should not be used with a DataSet because it actually may create a situation where the DataSet (in memory) is "updated", but not the disk database file, and later when you use "Update", vb thinks the changes have already been made. This was mentioned in another topic in this group, and in a book "Programming VB.Net" by Balena. I don't understand the whole thing, but I'm going to keep track of your thoughts to see if I understand them better later on. Rich wrote: Show quoteHide quote > Interesting that not a lot of people are using the datagridview object yet. > Anyway, here is what I do. In my example (from an app I am currently working > on) I add data to the new row to the datagridview. The trick is to add the > row to the underlying dataTable which is the datasource of the datagridview: > > Private Sub dgrModSubDetail_CellEndEdit(ByVal sender As Object, ByVal e As > System.Windows.Forms.DataGridViewCellEventArgs) Handles > dgrModSubDetail.CellEndEdit > Dim dr As DataRow > If e.RowIndex > dsWeb.Tables("modSubDetail").Rows.Count - 1 Then > dr = dsWeb.Tables("modSubDetail").NewRow > dsWeb.Tables("modSubDetail").Rows.Add(dr) > dsWeb.Tables("modSubDetail").AcceptChanges() > End If > End Sub > > e is the datagridview cell event arg for the CellEndEdit event of the > datagridview. I have observed that the CellEndEdit event is the last event > to fire when you leave a datagridview. e returns the row index (and also > column index). If the row index is greater than the number of rows in the > underlying datatable, I add a new datarow to the underlying datatable. You > can edit the datarow directly from/through the datagridview. This is very > convenient because you don't have to do the dr.Item(0) = ... like in vb2003. > Once you get the hang of the datagridview - it is real nice. Note: I am open > to suggestions here if my method is on the kludgy side. > > Rich > > "b**@datasync.com" wrote: > > > Can anyone tell me the best way to update a dataset while it is being > > edited/viewed in the DataGridView control? Is this something that > > should be inserted into one of the grid's events? or should you update > > after closing the grid/form, etc.? > > > > Also, can you tell me the best book to buy that fully explains the > > DataGridView control? > > > > Thanks. > > > >
How to Send an SMS
URI IsFile Streaming a file to text? How to force upper case in a DataGridView column? Dealing with NULL values in Integer fields Mulples threads and impersonation What's the Best Startup Scenario for Unattended Server Execution? Handle pointers from delphi client to a vb.net dll VB.net 2005 splash screen writing a text in a file in vb.net not working properly |
|||||||||||||||||||||||