简体   繁体   中英

Control is not getting focused on Keyup event

Hi all I have created a dynamic combo box with a Textbox and a button to appear as dropdown style, every thing works fine but I handled keyup event for the textbox so that when user enter some text I will search for the results and display them

 private void textBox1_KeyUp(object sender, KeyEventArgs e)
 {
     //Some code to filter my data 
     textBox1.Focus();
 }

But I am unable to set the focus Immediately back to the textbox after results getting displayed so can some one help me

Code I used is from here

http://www.planetsourcecode.com/vb/scripts/showcode.asp?txtCodeId=8554&lngWid=10

I have found that the Focus() method is a bit flaky.

Other options:

textBox1.Select(textBox1.Text.Length - button1, 1);

...or simply:

textBox1.Select();

If you can verify that something else is going wrong, then this might be off base, otherwise you might simply be fighting weirdness.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM