By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,115 Members | 898 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,115 IT Pros & Developers. It's quick & easy.

Updating a DataSet while using DataGridView

P: n/a
bob
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.

Jun 15 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"bo*@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.

Jun 15 '06 #2

P: n/a
bob
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:
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

"bo*@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.


Jun 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.