fedeteka fedeteka - 1 year ago 119
Vb.net Question

Textbox: missing first character typed on the TextBox

I have 2 text boxes to accept info but only one of them is need at the same time (One is for selection of the first letter and the other is for selection of any part of the name)

So I need to delete the text of the other textbox when the user start typing on the textbox

Something like this work:

Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged

TextBox1.Text = ""

End Sub

But there's a problem, the first character the user type is not displayed, I think is because the first character typed is used to launch the event.


TextBox1.Text = "A"
when the user click on TextBox2 and type michael the "m" is lost

I don´t want to use the "GotFocus" event because a simple TAB pulsed to jump from TextBox1 to another control can delete the text on TextBox1 when the user stop on TextBox2, even if he don´t want to type anything there

How can I manage this mistake?

Answer Source

Right answer:

From @Plutonix

"No user is going to expect this behavior and you will go mad trying to divine when to execute and when not to. A better thing might be to select the text on the Enter event - at least that has been seen before by users"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download