Updates from Windows form textbox

Mark

Member
Joined
Mar 8, 2005
Messages
9
Programming Experience
10+
I have placed both a group of textbox controls and a datagrid control on a Windows form. The fields in the datagrid are the same as those which populate the textbox controls. This form connects to a SQL Server database via Web services. All of the form's controls (both text boxes and datagrid) become fully populated when the form is opened. I can make changes to data in the datagrid and successfully save them back to the SQL Server database via an update Web method. However, I cannot save changes made in the text boxes. I am puzzled because both the text boxes and the datagrid are bound to the same dataset. Changes to that dataset are apparently only recognized and processed if they are made in the datagrid control. Can anyone suggest what might be at play here?
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
Since the textBoxes become populated when the form is opened, I'm assuming you're using dataBindings?
If so, you must first call the BindingManager.EndCurrentEdit method [Me.BindingContext(dataSource, DataMember).EndCurrentEdit] to save the changes made in the textBoxes.
One way to create this form is to use the dataForm Wizard, choosing the 'Single Records in Individual Controls' option; then add a dataGrid and set the DataSource and DataMember proerties. This will create the code for updating the dataSource as well if you choose the correct options in the wizard.
 

Mark

Member
Joined
Mar 8, 2005
Messages
9
Programming Experience
10+
Paszt said:
Since the textBoxes become populated when the form is opened, I'm assuming you're using dataBindings?
If so, you must first call the BindingManager.EndCurrentEdit method [Me.BindingContext(dataSource, DataMember).EndCurrentEdit] to save the changes made in the textBoxes.
One way to create this form is to use the dataForm Wizard, choosing the 'Single Records in Individual Controls' option; then add a dataGrid and set the DataSource and DataMember proerties. This will create the code for updating the dataSource as well if you choose the correct options in the wizard.


Thank you for your response. I am sure that you are steering me in the right direction. Yes, I am using dataBindings. I have tried every way I can conceive of to call the BindingManager.EndCurentEdit method but all to no avail; updates continue to be performed only if the datagrid has received focus before the update method is called. My code is pasted below. Can you spot anything that might be related to the problem? Again, may thanks for your efforts.

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.BindingContext(DscSelectedWO_Header).EndCurrentEdit()

If DscSelectedWO_Header.HasChanges() Then

Dim ws As New WindowsApplication1.localhost.WaSysService

ws.Credentials = System.Net.CredentialCache.DefaultCredentials

Dim diff_dsSelectedWO_Header As New WindowsApplication1.localhost.dsSelectedWO_Header

diff_dsSelectedWO_Header.Merge(DscSelectedWO_Header.GetChanges())

diff_dsSelectedWO_Header = ws.UpdateSelectedWO_Header(diff_dsSelectedWO_Header)

DscSelectedWO_Header.Merge(diff_dsSelectedWO_Header)

MsgBox("Updated", MsgBoxStyle.OKOnly, "Confirmation")

End If

End Sub
 
Top Bottom