I'm relatively new with VB.net, so please bear with me...
I have a tabpage with 28 textboxes in it. These textboxes will be loaded with data and maybe changed. There is a Save button on the form that will take the data from these textboxes and save them in a SQL database. Right now it saves EVERY time, regardless of what is in the textboxes. I want to save this data ONLY if there has been changes. Is this possible? If it were a dataGrid, a simple .HasChanges could be used, but this is textboxes. Because they are in a tabpage, they are all part of a group.

Any help is much appreciated!

Recommended Answers

All 3 Replies

Member Avatar for Unhnd_Exception

You need to work with the textchanged event of the text box

To detect changes you would need the textchange event below attached to all text boxes.

Public Class Form1
    Private HasChanges As Boolean

    Private Sub LoadTextBoxes()
        'Loading data into text boxes

        'The text would have been changed while loading. So reset the has changes
        HasChanges = False
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        HasChanges = True
    End Sub

    Private Sub Save()
        If HasChanges Then
            'save the data
        End If
    End Sub
End Class

Excellent. I'll try this out and let you know what I get.

I know this is marked solved, but thought I might add something for thought.

If you databind the text boxes to your underlying datatable, then you can use the datatables "GetChanges" function to determine if anything has changed. You could even use a currency manager to keep everything in sync in the event that the user uses another control to change records. It's not too difficult and saves tons of code-behind.

Regards,
Tony

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.