ComboBox - start with focus?

E

Ed Stewart

Hello. I first posted this on microsoft.public.dotnet.languages.csharp
because I found that linked to on some website. Since then, I've found this
windowsforms group. Sorry if you're reading this twice; it won't happen
again.

I'm creating an application that requires user input into a ComboBox, and
I'd like to have the cursor appear in this emtpy ComboBox when the
application starts. I had a plain TextBox, and the cursor started there
automatically; to implement a history feature, I've moved to a ComboBox, but
now the user needs to click on it before typing.

How do I set focus on this item? I've tried adding a null string and calling
comboBox.Focus() to no avail. I read somewhere the trick is to set the focus
to the editable text box contained within the ComboBox, but I haven't been
able to figure out how to do that.

Thanks,
-ed
 
K

Kevin Westhead

Ed Stewart said:
I'm creating an application that requires user input into a ComboBox, and
I'd like to have the cursor appear in this emtpy ComboBox when the
application starts. I had a plain TextBox, and the cursor started there
automatically; to implement a history feature, I've moved to a ComboBox, but
now the user needs to click on it before typing.

How do I set focus on this item? I've tried adding a null string and calling
comboBox.Focus() to no avail. I read somewhere the trick is to set the focus
to the editable text box contained within the ComboBox, but I haven't been
able to figure out how to do that.

Are there other controls on form? If so, what is the TabIndex of the
ComboBox? Typically the first control in the tab order of a dialog should
get focus when the dialog is displayed. In your form's Design view, click
View->Tab Order to see the overall tab order.
 
E

Ed Stewart

Are there other controls on form? If so, what is the TabIndex of the
ComboBox? Typically the first control in the tab order of a dialog should
get focus when the dialog is displayed. In your form's Design view, click
View->Tab Order to see the overall tab order.

There are a lot of other items in the form, and I never would have thought
of the Tab Order (I thought this was just a navigation control). I set the
ComboBox to 0 and now the cursor is right there when it starts up.

Thanks a lot,
-ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top