painted
asked on
Windows Form - Changes in DataGrid cause Button to change
I have a simple form (code below). What I would like to have happen is if the user makes changes to the information in the datagrid, then btnUpdate would change color. For example, the user changes the vendor address from 123 Main St to 456 Elm St. As soon as the user begins typing the change, btnUdate changes color to bring to the user's attention that they Update button needs to be clicked before exiting the program.
Is this possible?
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SqlDataAdapter1.Fill(DsVen dors1)
End Sub
Private Sub btnClearDataSet_Click(ByVa l sender As System.Object, ByVal e As System.EventArgs) Handles btnClearDataSet.Click
DsVendors1.Clear()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SqlDataAdapter1.Fill(DsVen dors1)
End Sub
Private Sub btnUpdate_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
If DsVendors1.HasChanges Then
SqlDataAdapter1.Update(DsV endors1)
End If
End Sub
Private Sub ExitToolStripMenuItem_Clic k(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Clic k
Me.Close()
End Sub
****** Private Sub DataGrid1_?????????(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.???????
If DsVendors1.HasChanges Then
btnUpdate.BackColor = Color.Red
btnUpdate.ForeColor = Color.White
End If
******* End Sub
End Class
Is this possible?
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SqlDataAdapter1.Fill(DsVen
End Sub
Private Sub btnClearDataSet_Click(ByVa
DsVendors1.Clear()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SqlDataAdapter1.Fill(DsVen
End Sub
Private Sub btnUpdate_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
If DsVendors1.HasChanges Then
SqlDataAdapter1.Update(DsV
End If
End Sub
Private Sub ExitToolStripMenuItem_Clic
Me.Close()
End Sub
****** Private Sub DataGrid1_?????????(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.???????
If DsVendors1.HasChanges Then
btnUpdate.BackColor = Color.Red
btnUpdate.ForeColor = Color.White
End If
******* End Sub
End Class
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry for not noting this before. I am using VS2005
ASKER
newyuppie,
Thanks for the code, but I think I'm in over my head here.
I dimmed dataGridView1 As DataGridView. Now I am getting an error "Handle clause requires a with event variable defined in the containing type or one of it's base types".
Can you help with this or lead me to a tutorial or sample?
Thanks for the code, but I think I'm in over my head here.
I dimmed dataGridView1 As DataGridView. Now I am getting an error "Handle clause requires a with event variable defined in the containing type or one of it's base types".
Can you help with this or lead me to a tutorial or sample?
dim withevents datagridview1 as datagridview
ASKER
ok, the error is gone, but it's still not working. Any other ideas?
Thanks,
donna
Thanks,
donna
I know its not what you asked but if you add the following it will update before the for is closed if the user hasn’t clicked the update button.
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormC losingEven tArgs) Handles Me.FormClosing
If DsVendors1.HasChanges Then
SqlDataAdapter1.Update(DsV endors1)
End If
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormC
If DsVendors1.HasChanges Then
SqlDataAdapter1.Update(DsV
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Sancler and newyuppie! Works like a charm. Took me a couple of tries to get this right, but the code and explanation got me on track. Thanks for all you help.
donna
donna
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q1018q.
The actual download link is
http://www.syncfusion.com/faq/winforms/Files/ForumTextChangedInDataGrid.zip
Roger