471,079 Members | 1,015 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How to use a datagridview to add/update/edit rows

I've read what's available here, but can't seem to make this work right. I'm
experimenting with components on a form, although I'd rather create the
pieces & assemble them in code, but that's another issue entirely.

I have a table in sql2k with an autoincrement column as primary index. It
also has a changeDate column with a trigger that updates to current datetime
when any column other than itself is changed.

Made a new form, followed Cor's tip & used Data to add a datasource.
Attached the bindingsource to the grid. To save the data, I'm doing this:

Private Sub DataGridView1_RowLeave(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.RowLeave
Try
Me.Validate()
Me.MoveTicketCrossReferenceBindingSource.EndEdit()
Me.MoveTicketCrossReferenceTableAdapter.Update(Me. MyDataset.MoveTicketCrossReference)
Catch ex As Exception
End Try
end sub

I can now view & edit the data, most of the time. But,
- the trigger usually does not fire, although sometimes it updates every row
with an identical date.
- The grid does not refresh -- gotta exit & open it.
- The autoincrement field increments up every time you enter the (*) row &
leave it, resulting in gaps in the primary index.
- Me.MoveTicketCrossReferenceBindingSource.Current is not recognized as a
property. I'd like to look at it to see whether certain things need to be
done.
Jul 28 '06 #1
1 7388
First off, I was struggling with entering a new row, and then updating
the database. Your code helped me fix that (RowLeave event). Thanks.
Regarding your issue, it sounds like you don't have a where clause in
your trigger that limits the date update to the current row. If all
rows are being updated to the current date, you need to limit the
update to the current row. For grid refresh, you'll need to trigger
this somehow in your form, I think. A refresh button perhaps. Or some
other form or control event that would trigger the refresh. Regarding
the autoincrement, I have a data grid view that is bound to a table
with an identity (autoincrement) column in a SQLExpress 2005 database.
I can click in the new row as much as I want, and event edit the
contents, but if I escape out, thereby canceling the insert, my
identity field does not increment. So that one I don't know.

JeremyGrand wrote:
I've read what's available here, but can't seem to make this work right. I'm
experimenting with components on a form, although I'd rather create the
pieces & assemble them in code, but that's another issue entirely.

I have a table in sql2k with an autoincrement column as primary index. It
also has a changeDate column with a trigger that updates to current datetime
when any column other than itself is changed.

Made a new form, followed Cor's tip & used Data to add a datasource.
Attached the bindingsource to the grid. To save the data, I'm doing this:

Private Sub DataGridView1_RowLeave(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.RowLeave
Try
Me.Validate()
Me.MoveTicketCrossReferenceBindingSource.EndEdit()
Me.MoveTicketCrossReferenceTableAdapter.Update(Me. MyDataset.MoveTicketCrossReference)
Catch ex As Exception
End Try
end sub

I can now view & edit the data, most of the time. But,
- the trigger usually does not fire, although sometimes it updates every row
with an identical date.
- The grid does not refresh -- gotta exit & open it.
- The autoincrement field increments up every time you enter the (*) row &
leave it, resulting in gaps in the primary index.
- Me.MoveTicketCrossReferenceBindingSource.Current is not recognized as a
property. I'd like to look at it to see whether certain things need to be
done.
Aug 3 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Bob | last post: by
3 posts views Thread by Prashwee | last post: by
6 posts views Thread by Miro | last post: by

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.