How many times does a control's MODIFIEDCHANGED event get TRIGGERED???

A

Alan Mailer

Ok, I'm pretty new to VB.Net, so please bear with me. Imagine the
Load event of one of my forms includes the following:

Dim ctrl as Control
Dim txtbox As TextBox

For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
txtbox = CType(ctrl, TextBox)
AddHandler txtbox.ModifiedChanged, AddressOf TextBoxChanged
End If
Next


....now here is what my "TextBoxChanged" routine looks like:

Private Sub TextBoxChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs)
MessageBox.Show("Hello World")
End Sub


....Now imagine my form has (amongst other controls) two textboxes on
it (Textbox1 and Textbox2). Here's what I'm finding:

After the form loads, if I type into Textbox1, I will successfully
trigger the "TextBoxChanged" routine.

But.... If I then give some other control on the form the Focus, then
return to Textbox1 and start typing again... this action will NOT
trigger "TextBoxChanged" again.

The same is true of Textbox2. The FIRST time I type into it, I will
trigger "TextBoxChanged", but at no other time during that instance of
my Form will I be able to trigger "TextBoxChanged" again.

I don't know whether I've explained this well, but can somebody take a
stab at telling me what might be going on here? Does a Textbox only
trigger ONE 'ModifiedChanged' event per instance of its containing
form?

Thanks in advance.
 
G

Guest

You'll only get one ModifiedChanged for each control unless you set the
Modified flag back to false. ModifiedChanged usually only gets raised
changed from false to true or true to false. Once at false it doesn't change
from true to false again unless you reset it to false.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top