Solved

List boxes and the arrow keys

Posted on 1998-12-10
5
231 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2016 VB code 9 115
Windows 10 start screen issues 9 55
Child Form in front 4 47
Export Data to Different .csv Files 26 105
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 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