Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

List boxes and the arrow keys

VB6 -- I have a listbox control and I want to be able to perform an action when the user presses the right or left arrow INSTEAD of having the focus move up or down the list.  I can tell when the user hits those keys by using keypress, keyup, or keydown, but I can't stop those keys from automatically moving the focus.  Any help is appreciated.
0
badreece
Asked:
badreece
1 Solution
 
watyCommented:
After you have trapped the key in keydown, eat the ky by assigning KeyAscii = 0
0
 
MirkwoodCommented:
Set the keycode to 0 in keydown

Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)
    If (KeyCode = 40) Then
        KeyCode = 0
    End If
End Sub

0
 
bflVijayCommented:
Hi,
    I am not very sure, but can't you try making the selected item color the same as the background colour, thus giving the impression that the key is not selected (I agree that it is a round about way to do it, but that's what I can think of at the moment.
    Or else you could try moving the focus back to the previous item ie deselect the selected item using VB coding. Is that not possible?
0
 
bflVijayCommented:
Hi,
    I am not very sure, but can't you try making the selected item color the same as the background colour, thus giving the impression that the key is not selected (I agree that it is a round about way to do it, but that's what I can think of at the moment.
    Or else you could try moving the focus back to the previous item ie deselect the selected item using VB coding. Is that not possible?
0
 
badreeceAuthor Commented:
The problem was that I was trying to set keyascii to 0 but using the KeyDown Event.  The KeyPressed Event won't recognize the arrow keys.  I changed it from KeyAscii to KeyCode and it started working.  You got me on the right path, though, and Its working now.  Thanks.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now