vb.net - TextBox1.TextChanged event shows MsgBox twice -
i have problem textbox1.textchanged event. code :
private sub textbox1_textchanged(sender object, e eventargs) handles textbox1.textchanged msgbox("txt changed") textbox1.clear() end sub
the problem msgbox shown twice, want show 1 time , clear textbox. how can that?
two ways:
temporarily remove handler prevent event firing again:
private sub textbox1_textchanged(sender object, e eventargs) handles textbox1.textchanged msgbox("txt changed") removehandler textbox1.textchanged, addressof textbox1_textchanged textbox1.clear() addhandler textbox1.textchanged, addressof textbox1_textchanged end sub
or
create field check if event originating itself:
dim textboxalreadychanging boolean = false private sub textbox1_textchanged(sender object, e eventargs) handles textbox1.textchanged if not textboxalreadychanging msgbox("txt changed") textboxalreadychanging = true textbox1.clear() textboxalreadychanging = false end if end sub
Comments
Post a Comment