Help with SendKeys

  • Thread starter Thread starter Keith Smith
  • Start date Start date
K

Keith Smith

When the user presses "Enter" on my comboBox, I would like for the selector
to go to the next comboBox. Since this is kind of like hitting the "tab"
key I thought I would just enable my KeyDown event for my comboBox with this
code...

SendKeys.Send(Keys.Tab);

This doesn't work. Any ideas why?
 
Nevermind, I found that I can use this code to make it work.

SendKeys.Send("{Tab}");


But I still wouldn't mind seeing any comments - am I doing this efficiently
or is there another way I should be doing this?
 
Keith,

What I would do is attach an event handler to the combobox for the Key
Up event. When you detect the enter key was pressed, call the
GetNextControl method on the combobox, and it will give the next control in
the tab order. Then, call Focus on that control. I think it is much
cleaner than using SendKeys.

Hope this helps.
 
Paul,

Unfortunately, that won't work, as it only works on container controls,
which the ComboBox is not (there is no such method on that type).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Paul E Collins said:
Keith Smith said:
[using SendKeys to tab to next control]

A nasty hack indeed! Try this:

this.ProcessTabKey(true);

P.
 
[ProcessTabKey] only works on container
controls, which the ComboBox is not

this.ProcessTabKey(true);
^^^^
But "this" is the Form that contains the ComboBox. It works fine here.

P.
 
What I would do is attach an event handler to the combobox for the Key
Up event. When you detect the enter key was pressed, call the
GetNextControl method on the combobox, and it will give the next control
in the tab order. Then, call Focus on that control. I think it is much
cleaner than using SendKeys.

Should I use KeyUp or KeyDown? or does it matter?
 
Since it's your app, it's your call. However, you'll find that most
applications have a tendency to user KeyUp. Either way, you should defintely
be using the Focus method in this situation.
 
Back
Top