robertb_NZ
Well-known member
I have a richtextbox that can be edited, also the text may change as a result of my program. I have some logic that I want to trigger when the text has been changed by editing, but I don't want the logic for changes caused by my program. Currently I solve this problem with the following rather clumsy code, in which I have a Boolean called "Edited" that I set false whenever my program logic makes a change: -
Dim Edited as Boolean = True ' Use together with Dirty to decide how to handle RTB.Text
...
' Somewhere in my program logic
Edited = false
RTB.Text = "Some new value"
...
Private Sub RTB_TextChanged(sender As System.Object, e As System.EventArgs) Handles RTB.TextChanged
' Event may be triggered by editing, or by processing like reading a file, parsing it, etc
If Edited = False Then ' Set true for File/Open, and program-caused changes during editing
Edited = True ' Maintain default value
Exit Sub
End If
...
I'd like something that behaves like TextChanged in ASP.NET, where its definition in that environment: -
"The TextChanged event is raised when the content of the text box changes between posts to the server"
means that program-caused changes don't raise the event. However I can't see any such event, and so it seems that I'm stuck with clumsy code like that above. Has anybody got a better idea?
Thank you, Robert
Dim Edited as Boolean = True ' Use together with Dirty to decide how to handle RTB.Text
...
' Somewhere in my program logic
Edited = false
RTB.Text = "Some new value"
...
Private Sub RTB_TextChanged(sender As System.Object, e As System.EventArgs) Handles RTB.TextChanged
' Event may be triggered by editing, or by processing like reading a file, parsing it, etc
If Edited = False Then ' Set true for File/Open, and program-caused changes during editing
Edited = True ' Maintain default value
Exit Sub
End If
...
I'd like something that behaves like TextChanged in ASP.NET, where its definition in that environment: -
"The TextChanged event is raised when the content of the text box changes between posts to the server"
means that program-caused changes don't raise the event. However I can't see any such event, and so it seems that I'm stuck with clumsy code like that above. Has anybody got a better idea?
Thank you, Robert