pull down combobpx

  • Thread starter Thread starter Ivan V via DotNetMonster.com
  • Start date Start date
I

Ivan V via DotNetMonster.com

Hi All:

How can I activate the spacebar to pull down the combobox?

For instance, once the tab stopped at the combobox, suppose i can use dnarrow
or F4 to pull down the combobox to make selection, but instead of these 2
keys, I want to use spacebar, can I do that?

Best rgds,
Ivan Vong
 
Ivan V via DotNetMonster.com said:
How can I activate the spacebar to pull down the combobox?

Set the control's 'DroppedDown' property to 'True'.
 
Hi All:

How can I activate the spacebar to pull down the combobox?

For instance, once the tab stopped at the combobox, suppose i can use dnarrow
or F4 to pull down the combobox to make selection, but instead of these 2
keys, I want to use spacebar, can I do that?

I would subclass the regular combobox and handle the OnKeyDown method:

Public Class MyComboBox
Inherits ComboBox

' abstract method. just call base class method
Protected Overrides Sub RefreshItem(ByVal index As Integer)
MyBase.RefreshItem(index)
End Sub

' abstract method. just call base class method
Protected Overrides Sub SetItemsCore(ByVal items As
System.Collections.IList)
MyBase.SetItemsCore(items)
End Sub

Protected Overrides Sub OnKeyDown(ByVal e As KeyEventArgs)
If e.KeyCode = Keys.Space Then
Me.DroppedDown = Not Me.DroppedDown
e.Handled = True
End If
End Sub
End Class

All this does is that when the space key is pressed, it will toggle the
dropdown to either on or off.
 
both method is not working!

The code was copied directly out of a working project. Could you give
more detail as to what "is not working" means? Are you getting errors?
Can you provide some sample code?

This is a winform app, correct?
 
Yes, it's a vb.net application. I just simply add the code that you provided
to me. My comob box named Type, and nothing had changed when the code has
been added!!!
 
Yes, it's a vb.net application. I just simply add the code that you provided
to me. My comob box named Type, and nothing had changed when the code has
been added!!!

You also need to change the VS.NET generated code. Right now it's
creating a standard System.Windows.Forms.ComboBox. You'd need to change
that to "MyComboBox" (if you use the sample code I provided).
 
Thanks Patrick, it works great for me now. How about to activate the up arrow
and down arrow in our keyboard in a window from as the function of tab key?
 
Thanks Patrick, it works great for me now. How about to activate the up arrow
and down arrow in our keyboard in a window from as the function of tab key?

I'm not sure what you're asking. Do you want the up/down arrow keys to
allow you to move focus around the form like TAB and SHIFT+TAB? Or do
you want the TAB and SHIFT+TAB keys to act like the up/down arrow keys?
 
It's the former one which the up/down arrow keys allow me to move focus
around like the TAB and SHIFT + TAB.
Thanks for your attention!
 

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

Back
Top