4
I’m having a problem changing the input focus between the TextBox
of my application.
The problem is actually this: tb_Estados
has a AutoCompleteMode = AutoCompleteMode.Append
and a AutoCompleteSource = AutoCompleteSource.CustomSource
. So far, no problem.
Things start to go wrong on the principle that when trying to change textbox with by pressing enter in the event KeyPress
of TextBox
, simply "nothing happens".
private void tb_Estados_KeyPress_1(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar == ((char)(Keys.Enter))))
{
tb_Cidades.Focus();
}
}
The focus doesn’t change to the tb_Cidades
, but it does remain in the tb_Estados
.
What I noticed occurs is that the text tb_Estados
is all selected by pressing the Enter key instead of changing the input focus. That is, it does not change the focus, it just selects (if there is something inserted) the text of the tb_Estado
. If you have nothing inserted, it simply selects the " " and does not switch to the tb_Cidades
.
I tried to use the .Select()
instead of .Focus()
, but it didn’t help.
I also tried to use the SendKeys
to send the command to {"Tab"}
, but it didn’t work either.
I appreciate the attention and possible solutions of all!
Try putting a
e.Cancel = true
after tb_Cidades.Focus();– Victor Laio
You can always try
SelectNextControl(tb_Estados, true, true, true, true);
. But anyway it seems to me that there is some property in controltb_Cidades
that is preventing the focus.– João Martins
Try putting in Keydown if (e.Keycode == Keys.Enter) { Sendkeys.Send("{TAB}"); e.Handled = true; }
– Andrew Alex