Solved

List boxes and the arrow keys

Posted on 1998-12-10
5
232 Views
Last Modified: 2010-05-03
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
Comment
Question by:badreece
5 Comments
 
LVL 14

Accepted Solution

by:
waty earned 100 total points
ID: 1449276
After you have trapped the key in keydown, eat the ky by assigning KeyAscii = 0
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1449277
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
 

Expert Comment

by:bflVijay
ID: 1449278
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
 

Expert Comment

by:bflVijay
ID: 1449279
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
 

Author Comment

by:badreece
ID: 1449280
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question