473,388 Members | 1,235 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 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 7664
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: P K | last post by:
I have a Datagridview. I only edit couple of columns. No new rows are added. I need to know the count of "rows" that were modified. how do I acheive this?
2
by: bob | last post by:
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...
0
by: schoultzy | last post by:
Hello Everyone, I have been trying to figure this one out for two days now. I have created a DataGridView which is populated by an ObjectDataSource. My problem occurs when I attempt to use the...
3
by: Bob | last post by:
Hi, FrameWork 2.0 Quick and dirty job so I thought I would do it all on the UI as quick and easy as possible. I got the datagridview to display my Access databaseview by using the Datasources...
3
by: Prashwee | last post by:
Hello All In my windows application I am using DataGridView as my grid control. I populated let's say 10 rows of data and modified 3 random rows. I need to put some sort of Edit Marker in the...
4
by: Hexman | last post by:
Hello All, I'd like to find out the best way to add a cb column to a dgv and process efficiently. I see at least two ways of doing it. ------------------------------- 1) Add a cb to the dgv,...
5
by: DanThMan | last post by:
The situation: * I have a ButtonColumn in a DataGridView. * When the user preses one of the buttons, a dialog appears. * Based on what the user selects in the dialog, data is entered...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a...
15
by: javatech007 | last post by:
I am creating a bank customer's details application. The information is stored on a Microsoft Access file and I was able to make the information appear on my VB application through text boxes and a...
6
by: Miro | last post by:
Sorry for the cross post. I am stuck. I have a datagridview for poker rounds. Basically there are 3 columns in this datagridview. "Round" "SmallBlind" "BigBlind" I have an issue when I tab...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.