prompting when changes have been made to a text box

ninjaimp

Well-known member
Joined
Jun 13, 2007
Messages
80
Programming Experience
1-3
HI

I have an application that contains certain editable fields (textboxs) and what i want to do is know when someone has changed or entered new text.

What i done was in the 'TextChanged' part of a text box was this:
VB.NET:
Private Sub txtCNotes_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCNotes.TextChanged

ChangesMade = True

End Sub

now 'ChangesMade' is a global boolean variable which in its first state is set to false and then true if a change is made.

no on the exit of the program or if they navigate away from the record i have this bit of code:
VB.NET:
If ChangesMade = True Then
MsgBox("Do you wish to save your changes?")
End If


but the problem is it is just giving that message, regardless of any changes or not.

I wondered if anyone had any ideas?

Regards

Simon
 
Last edited by a moderator:
Somewhere the ChangesMade variable is being set to True, do a document search for the variable and you'll probably find the spot that it's always setting it to True pretty quickly
 
i have checked all code and the only places where it is set to true is on the 'TextChanged' element of the text box. dont figure?
 
is the textbox bound to any data sources? when the form first loads, the textbox is empty and then the data is placed in the text property which would fire the TextChanged event which would set the boolean to True, thus it's always true.
 
solved - well, sort of

just changed the state on the text box from changed to got focus, even though it may have not changed it still knows something has been done!
 
In the form's shown event set the boolean to False. If the form has the ability to move from record to record in the dataset, you'll need to set the boolean to False after the next record is shown.
 
Back
Top