472,993 Members | 3,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 software developers and data experts.

Updating a DataSet while using DataGridView

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
2 24460
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Son of beach | last post by:
I am the beginner of XML. Somebody suggests me to use JDOM for read/ write XML file. I success to use JDOM for reading XML, but get difficulty to update a XML file. Do you have any simple...
1
by: tkaleb | last post by:
I have to create output file in a text, MS Access, MS Excel and .dbf format from C# Win/ADO.NET application. Data are collected in DataSet and there is no problem to make text file. However, I have...
1
by: P | last post by:
Hello, I am having a difficult time updating a record via a stored procedure using the gridview and sqldatasource. I cannot seem to be able to find a way to set everything up so that I can pass...
10
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1)...
1
by: zoneal | last post by:
I retrieved the following function from VB.NET help and added a few statements for updating the datasource. But, it does not actually commence the InsertCommand property of the DataAdapter in order...
1
by: batista | last post by:
Hello all, I have a third praty grid control...named C1grid. Im using it in one of my apps.. Now, I have bind this grid to a custom dataset class named "DataViewEx". The code of the class is...
0
by: Dharmen Patel | last post by:
I am using Enterprise Library 2006 , Data Access Application Blocks. 1. I am connecting to Oracle 9i database using DAAB. 2. I retrieve a dataset using the following code in VB.NET. ...
1
by: aritra2008 | last post by:
Hi, Can anybody tell me how can I insert multiple data in a data table of a database using DataGridView control in VB/ASP.Net? It is very urgent for me to know. Kindly anybody help me...
0
by: mfranz | last post by:
Hi to everybody, I think I'm really confused with dataset and datagridview. If I modify cell values with a mouseclick, it works fine, but if I assign a value to a datagridview like this: ...
1
by: progvar | last post by:
Hi i want to update data in database using datagridview actually i am displaying the data in datagridview and after that i want to update some rows data directly modifying the displayed data into...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.