Datagridview textbox Binding update problem

dashley

Well-known member
Joined
May 27, 2005
Messages
59
Location
Tennessee
Programming Experience
10+
I have a bound datagridview (DGV) listing 3 col's of data from my datasource. On the same form I have multple bound Textboxes bound to the same dataset. When I click on a different row on my DGV the textboxes change to refelct the correct information based on the selected datagridview row. IF I update a row cell on the DGV and click my save button all goes well and the DGV updates the dataset just fine.

If I change the text in tha textbox and click save the Textboxdata stays changed and the DGV is changed but my Datbase isn't updataing unless I go over to the DGV after changing the textbox and change the DGV to a different row.

I've searced for the answer but cant find any information on this problem.

Any Ideas?

Thanks
 
I am no expert, but here goes. The BindingNavigator that has the save button you are clicking updates the table based on the data in the DGV, not the text box. If you enter data in the text box, you see the change in the DGV, but it is not saved in the DGV until you move to another cell. If you want to enter data in the text box, you need to write code to save it when you exit the text box. Try this:

VB.NET:
Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
     Me.DataBindingSource.EndEdit()
     Me.DataTableAdapter.Update(Me.DataSet.Data)
End Sub

This says that when you leave TextBox1, stop editing with the DataBindingSource your DGV is bound to, and use the DataTableAdapter to update the data 'source' from the table DataSet.Data.
Hope this helps.
 
c,

Thank you. I was missing the databindingsource.endedit.
Since I had a bunch of texboxes bound I just added this in my save button event

Me.DataGridView1.EndEdit()
Me.CustomersBindingSource.EndEdit()
Me.CustomersTableAdapter.Update(Me.DataSet1.customers)

This way whatever I edit, DGV or TB, one size fits all. I tested it and it works great.

Thanks Again.

Dan


 
Back
Top