stackoverflow on EndCurrentEdit

W

Wan

Dear Group,
I have a small application with two buttons and three textboxes
with databinding.
One of the textboxes has a ¡§textchanged¡¨ event and other 2 textboxes
are attached with the same events. If I type into any textboxes then
btnSave and btnExit will enable/disable respectively. The problem is
that in some instances ¡¥text changed event¡¨ hits endless loop and
causes an stackoverflow message. Is there a way to solve this
problem? I¡¦d appreciate any help. Thanks

Private sub Form1_Activated (..)
¡K
Text1.Databindings.Add(New Binding(¡§Text¡¨, ds.tables(0), ¡§City¡¨)
Text2.Databindings.Add(New Binding(¡§Text¡¨, ds.tables(0), ¡§State¡¨)
Text3.Databindings.Add(New Binding(¡§Text¡¨, ds.tables(0), ¡§Zip¡¨)

Addhander Text1.TexChnaged, AddressOf Form1_TextChanged
Addhander Text2.TexChnaged, AddressOf Form1_TextChanged
Addhander Text3.TexChnaged, AddressOf Form1_TextChanged
End sub

Private sub Form1_TextChanged(..) Handles textbox1_TextChanged
Me.bindingCntact(ds).EndCurrentEdit() „² causes endless lop
If ds.HasChanged = True then
btnSave.Enabled = True ¡¥ enable save button
btnExit.Enabled = False ¡¥ disable exit button
Endif
End sub
 
A

Alan Mosley

It would seem that changing text fires the event that changes text that once
again fires event.

You may need to record the value and see if it is fact diffrent to the new
value, and if not then cancel the event

Dear Group,
I have a small application with two buttons and three textboxes
with databinding.
One of the textboxes has a ¡§textchanged¡¨ event and other 2 textboxes
are attached with the same events. If I type into any textboxes then
btnSave and btnExit will enable/disable respectively. The problem is
that in some instances ¡¥text changed event¡¨ hits endless loop and
causes an stackoverflow message. Is there a way to solve this
problem? I¡¦d appreciate any help. Thanks

Private sub Form1_Activated (..)
¡K
Text1.Databindings.Add(New Binding(¡§Text¡¨, ds.tables(0), ¡§City¡¨)
Text2.Databindings.Add(New Binding(¡§Text¡¨, ds.tables(0), ¡§State¡¨)
Text3.Databindings.Add(New Binding(¡§Text¡¨, ds.tables(0), ¡§Zip¡¨)

Addhander Text1.TexChnaged, AddressOf Form1_TextChanged
Addhander Text2.TexChnaged, AddressOf Form1_TextChanged
Addhander Text3.TexChnaged, AddressOf Form1_TextChanged
End sub

Private sub Form1_TextChanged(..) Handles textbox1_TextChanged
Me.bindingCntact(ds).EndCurrentEdit() „² causes endless lop
If ds.HasChanged = True then
btnSave.Enabled = True ¡¥ enable save button
btnExit.Enabled = False ¡¥ disable exit button
Endif
End sub
 
J

Jack Jackson

Dear Group,
I have a small application with two buttons and three textboxes
with databinding.
One of the textboxes has a ??textchanged?? event and other 2 textboxes
are attached with the same events. If I type into any textboxes then
btnSave and btnExit will enable/disable respectively. The problem is
that in some instances ??text changed event?? hits endless loop and
causes an stackoverflow message. Is there a way to solve this
problem? I??d appreciate any help. Thanks

Private sub Form1_Activated (..)
?K
Text1.Databindings.Add(New Binding(??Text??, ds.tables(0), ??City??)
Text2.Databindings.Add(New Binding(??Text??, ds.tables(0), ??State??)
Text3.Databindings.Add(New Binding(??Text??, ds.tables(0), ??Zip??)

Addhander Text1.TexChnaged, AddressOf Form1_TextChanged
Addhander Text2.TexChnaged, AddressOf Form1_TextChanged
Addhander Text3.TexChnaged, AddressOf Form1_TextChanged
End sub

Private sub Form1_TextChanged(..) Handles textbox1_TextChanged
Me.bindingCntact(ds).EndCurrentEdit() ?? causes endless lop
If ds.HasChanged = True then
btnSave.Enabled = True ?? enable save button
btnExit.Enabled = False ?? disable exit button
Endif
End sub

You could have a flag in the form, like:
Private m_textChangedActive As Boolean = False

Private sub Form1_TextChanged(..) Handles textbox1_TextChanged
If m_textChangedActive Then
Return
End If
m_textChangedActive = True
Me.bindingCntact(ds).EndCurrentEdit() ?? causes endless lop
If ds.HasChanged = True then
btnSave.Enabled = True ?? enable save button
btnExit.Enabled = False ?? disable exit button
Endif
m_textChangedActive = False
End sub
 
W

Wan

Thanks Alan Mostey and Jack Jackson for the great feedback. Jack -
Your code snippet is helpful, however, m_textChangedActive needs to
set to true somewhere in order to fire "TextChanged" event. Thanks
for your time.
 
J

Jack Jackson

Thanks Alan Mostey and Jack Jackson for the great feedback. Jack -
Your code snippet is helpful, however, m_textChangedActive needs to
set to true somewhere in order to fire "TextChanged" event. Thanks
for your time.

I don't understand your comment.

Initially m_textChangedActive is False, so when the event handler is
called it sets the field to True and proceeds. If the event is
triggered while the event handler is executing, the handler will exit
immediately. At the end the field is set to False.

Nothing about m_textChangedActive has anything to do with the firing
of the TextChanged event, just about what code is executed when the
event fires.
 

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

Similar Threads


Top