Solved

List boxes and the arrow keys

Posted on 1998-12-10
5
229 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
Comment Utility
After you have trapped the key in keydown, eat the ky by assigning KeyAscii = 0
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now