Connecting Tech Pros Worldwide Forums | Help | Site Map

combobox down list

Familiar Sight
 
Join Date: Feb 2007
Posts: 142
#1: Feb 28 '07
can anybody tell me what is the code to show the drop down list in combobox when press the down arrow in the keyboard? i am using VB6.



Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#2: Mar 1 '07

re: combobox down list


Quote:

Originally Posted by joemo2003

can anybody tell me what is the code to show the drop down list in combobox when press the down arrow in the keyboard? i am using VB6.

Well, this sort of works, except that the list disappears again when you try to scroll down it. Might be a place to start, though.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
  2.   If KeyCode = vbKeyDown Then
  3.     Beep
  4.     KeyCode = vbKeyF4
  5.   End If
  6. End Sub
Member
 
Join Date: Jan 2007
Location: Kerala/Dubai
Posts: 85
#3: Mar 1 '07

re: combobox down list


This is not a good practice. Use this code on the gotfocus event this will be better
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo1_GotFocus()
  2. SendKeys "{F4}": DoEvents
  3. End Sub
Familiar Sight
 
Join Date: Feb 2007
Posts: 142
#4: Mar 1 '07

re: combobox down list


the list do scroll down, but it can not select item when press the down key. how to make it press the downkey one time is scroll down the list, and press again then move the selection in the combobox? just like the google toolbar.

thanks

Quote:

Originally Posted by Killer42

Well, this sort of works, except that the list disappears again when you try to scroll down it. Might be a place to start, though.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
  2.   If KeyCode = vbKeyDown Then
  3.     Beep
  4.     KeyCode = vbKeyF4
  5.   End If
  6. End Sub

Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#5: Mar 1 '07

re: combobox down list


Quote:

Originally Posted by joemo2003

the list do scroll down, but it can not select item when press the down key.

Well, that's what I said. I just threw that together to provide you something to work with. It's certainly not a complete solution.

The alternative suggested by sukeshchand may be a much better way to go.

The real problem with using the down arrow to open the list is that you have to be able to tell whether the list is currently displayed or not. One possibility would be to set a flag in the GotFocus event, then only do the "drop-down on down arrow" the first time the key is pressed. But this is only a small improvement, as you still couldn't tell for sure whether you would be opening or closing the list.
Member
 
Join Date: Jan 2007
Location: Kerala/Dubai
Posts: 85
#6: Mar 3 '07

re: combobox down list


Try to do like this
Here i am not recomented to use this because this is not a proper way to do that.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
  2. If KeyCode = vbKeyDown Then
  3.     KeyCode = 0
  4.     DoEvents
  5.     SendKeys "{escape}"
  6.     DoEvents
  7.     SendKeys "{f4}"
  8.     DoEvents
  9.     KeyCode = vbKeyDown
  10.     DoEvents
  11. End If
  12. End Sub
Familiar Sight
 
Join Date: Feb 2007
Posts: 142
#7: Mar 3 '07

re: combobox down list


Thanks a lot



Quote:

Originally Posted by sukeshchand

Try to do like this
Here i am not recomented to use this because this is not a proper way to do that.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
  2. If KeyCode = vbKeyDown Then
  3.     KeyCode = 0
  4.     DoEvents
  5.     SendKeys "{escape}"
  6.     DoEvents
  7.     SendKeys "{f4}"
  8.     DoEvents
  9.     KeyCode = vbKeyDown
  10.     DoEvents
  11. End If
  12. End Sub

Reply