|
-
Jun 20th, 2012, 11:26 AM
#1
Thread Starter
Addicted Member
attach code to DataGridView
I have a DataGridView setup on my form that connects to an Access database. When new data is entered in the DataGridView, the Access database is not automatically updated. I wrote some code that updates the access database by clicking a button. I'd like to attached that code every time I change rows on the DataGridView. Pressing a button every time to update is a hassle and sometime you forget. How do I do that?
-
Jun 20th, 2012, 11:31 AM
#2
Re: attach code to DataGridView
Take a look at the DataGridView_RowsAdded Event. I would put your code that you use in your update button into a sub and call it when needed, like so:
Code:
Private Sub updateCode()
MessageBox.Show("I just used my update sub")
End Sub
Private Sub DataGridView1_RowsAdded(sender As Object, e As System.Windows.Forms.DataGridViewRowsAddedEventArgs) Handles DataGridView1.RowsAdded
Call updateCode()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Call updateCode()
End Sub
Edit - Mind you, you don't have to use Call in "Call updateCode()". I do that outta habbit, it's just easier for me to read.
Last edited by dday9; Jun 20th, 2012 at 11:41 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|