Improve company productivity with a Business Account.Sign Up

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

Question About KeyUp and ListBoxes

I have a list box that is being monitored for key events.  When I tab to the list box I can use the arrow keys to select a record.  With a record selected, I want to trigger an action when the Return key is pushed.  The event does not fire on the first push; it fires on the second.  Why is this?

Mike

0
shacho
Asked:
shacho
  • 4
  • 2
  • 2
5 Solutions
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
why not use KeyDown ?

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Why are you using the Return key in the List box?
0
 
shachoAuthor Commented:
>why not use KeyDown ?
Tried KeyDown.  It works.  But why should KeyDown work on the first Enter and not KeyUp?
I chose KeyUp because I figured it was good policy to run code after key events were concluded
and KeyUp should logically run after KeyDown.

>Why are you using the Return key in the List box?
The listbox is a search results list.  I want people who prefer to use the keyboard over the mouse
to be able to launch the viewer for the selected record with the Return key in case they don't want
to double-click.

Mike
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Not sure why Key Down works over Key Up ... but it's still a valid event ... and for most applications I can think of, that is what I use. Actually on my test for, Key Up works on the first time.  However ... if nothing is selected and I tab into the list box ... and hit down arrow ... it selects the first item ... and so on.  BUT ... if I hit Enter at any time ... it goes to the next control in the tab order!

mx
0
 
rockiroadsCommented:
the difference I thought was

keydown - user presses a key
keyup - user releases a key

so explains why keydown gets called first, as you have concluded yourself.

But it doesnt need two pushes, unless maybe you have caught it elsewhere first?
Have you a form capture event?

I for one prefer the use of keypress but thats not going to answer your question now is it, lol.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
However ... Keypress does not catch all codes ...

Yes ... sure, that is the difference between the two ...

mx
0
 
rockiroadsCommented:
no, though it does catch return key but if you want to catch the use of shift, ctrl etc then you have to use the other key events.
0
 
shachoAuthor Commented:
Well, I'm gonna chalk it up to plain old bugginess because I think KeyUp should work.  Thanks for your suggestions.

Cheers,

Mike
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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