Question StackOverflowExecption was unhandled

Joshdbr

Well-known member
Joined
Apr 7, 2011
Messages
211
Location
Montana, USA
Programming Experience
5-10
Hi, thanks for reading,

What I have is a user control that has two RichTextBoxes. In the user control, there is RichTextBox1's TextChanged event, I want it to set RichTextBox2's Text to the same as RichTextBox1's Text, I'm currently using:

VB.NET:
RichTextBox2.Text = RichTextBox1.Text

The user control is on the main form, when I run the application and type I get this error:

StackOverflowExecption was unhandled

An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll


Thanks in advance!
-Josh

Also, it doesn't make any difference whether it is in a seperate sub or not.
 
I'm guessing that you have the converse operation too, so one change triggers the other, which triggers the other, which triggers the other, and on and on like that until the stack overflows. In that case, you should probably use a Boolean flag to indicate not to trigger the converse operation each time.
 
Thanks for the reply, this is my second version of this particular application and I was wondering why I had it on the KeyUp event instead of the TextChanged event in the previous version :) Changing it back to KeyUp worked fine.

But I'm still not sure what was causing the overflow, it was setting box2 to box1, only box1 has the TextChanged event. Am I missing something?

Thanks for you help
-Josh
 
Thanks for the help, I will check into it.

-Josh
 
Back
Top