Link to home
Start Free TrialLog in
Avatar of badreece
badreece

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of waty
waty
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mirkwood
Mirkwood

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

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?
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?
Avatar of badreece

ASKER

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.