Forcing TextChanged event on setting Control.Text

Z

Zytan

TextChanged is only called when the user modifes a control's text, not
if the program does.

How can I make it be called when the program modifies the text?

Zytan
 
Z

Zytan

Tomb,

Thanks for the reply.

I can't just call TextBox1.TextChanged(), since it's an event. I need
to use RaiseEvent to do that, which can only be used on declared
events.

I could call TextBox1_TextChanged(), the function that the event
invokes. But, what do I pass it as arguments?

Even if I CAN pass the proper arguments, I'd have to make this call in
*every place* that I manually change the text. <sigh>

There has got to be a better way that just invokes the event when the
text is changed, no matter WHO changes it.

Zytan
 
R

rowe_newsgroups

TextChanged is only called when the user modifes a control's text, not
if the program does.

How can I make it be called when the program modifies the text?

Zytan
TextChanged is only called when the user modifes a control's text, not
if the program does.

Are you sure? The following works fine for me...

Private Sub TextBox1_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Me.TextBox1.BackColor = Color.Red
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Me.TextBox1.Text = "hello"
End Sub

As soon as the button is clicked, the _TextChanged Event Fires,
turning it red.

Thanks,

Seth Rowe
 
R

rowe_newsgroups

Tomb,

Thanks for the reply.

I can't just call TextBox1.TextChanged(), since it's an event. I need
to use RaiseEvent to do that, which can only be used on declared
events.

I could call TextBox1_TextChanged(), the function that the event
invokes. But, what do I pass it as arguments?

Even if I CAN pass the proper arguments, I'd have to make this call in
*every place* that I manually change the text. <sigh>

There has got to be a better way that just invokes the event when the
text is changed, no matter WHO changes it.

Zytan
I could call TextBox1_TextChanged(), the function that the event
invokes. But, what do I pass it as arguments?

TextBox1_TextChanged(me.TextBox1, EventArgs.Empty)

Thanks,

Seth Rowe
 
B

Branco Medeiros

Zytan said:
TextChanged is only called when the user modifes a control's text, not
if the program does.

How can I make it be called when the program modifies the text?

I don't see this behavior. From what I know, the TextChanged event
will be called whenever you change the text, regardless if by your
code or from the UI...

Maybe you need to describe your exact problem.

Regards,

Branco.
 
Z

Zytan

Are you sure? The following works fine for me...
...

As soon as the button is clicked, the _TextChanged Event Fires,
turning it red.

Whoa! You are absolutely right! Thanks for the information, Seth!

What I am doing in response to the text changed event is determining
if the file that is typed into it exists or not (yes, I know, there
could be issues with slowing down the GUI with networks, etc., but
this is just a quick 'n dirty application, so it's ok for now).

So, obviously my code is being run, but the code that is being run
isn't working. Which is strange, since I am initializing the text box
to contain text of an existing file. If I change one character in it,
and then undo that change, (i.e. causing the USER to create the exact
text that the program does), my code will work! Hmm... must be
something to do with the Form1_Load() event... I'll mess around and
post back in a bit...

Zytan
 
Z

Zytan

I could call TextBox1_TextChanged(), the function that the event
TextBox1_TextChanged(me.TextBox1, EventArgs.Empty)

Thanks again, Seth. You're a great help.

Zytan
 
Z

Zytan

Maybe you need to describe your exact problem.

Branco, I would have included more information at the start, but I
didn't think it was relevant.

I simply goofed... The response to the TextChanged() event was to see
if the filename typed in existed or not, and respond with a visible
reaction. It appears something else was overriding that initial
programmatic reaction (in Form1_Load), so I didn't see it. It was
working all along... <sigh>

You guys have been a great help. Thanks again!

Zytan
 

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