|
-
Apr 22nd, 2002, 07:21 PM
#1
Thread Starter
New Member
Key_Press for Listboxes
Hello all!!!
My listbox is linked to an SQL server DB, and the listbox is populated by a "look-up" table. So here's what I need to do:
When the user presses a number from 1 to 50 I need the selection to jump to the listindex property that matches the number inputted.
Listbox.style = checkbox
For example, if the user presses 15 then the selection should jump to item that has the listindex of 15 and then check the item off.
How would I go about this ??? Any help is very much appreciated!
Jay
-
Apr 22nd, 2002, 07:49 PM
#2
PowerPoster
Well this will work if the index is 99 or under. You can modify it to accept larger numbers. How it works is the user enters thier number, single digits begin with a 0, anything over 9 is entered normaly.
For example. To enter the index of 8 you would press 0 then 8, to enter 15 you would press 1 then 5.
VB Code:
Private Sub List1_KeyPress(KeyAscii As Integer)
Static Pressed As Integer, MoveToChr As Integer
Pressed = Pressed + 1
If Pressed = 2 Then
MoveToChr = MoveToChr & Chr(KeyAscii)
Else
MoveToChr = Chr(KeyAscii)
Exit Sub
End If
Pressed = 0
List1.ListIndex = MoveToChr
List1.Selected(MoveToChr) = False
End Sub
Last edited by Arc; Apr 22nd, 2002 at 07:56 PM.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Apr 23rd, 2002, 01:14 AM
#3
-
Apr 23rd, 2002, 11:15 AM
#4
Thread Starter
New Member
Hi Arc,
Thanks in advance for the code... I haven't tried it out yet because I just arrived at work. Please do not be saddened I really do appreciate your help, and all the help I get! Thanks again and I'll let you know in a few minutes how it goes!
-
Apr 23rd, 2002, 11:57 AM
#5
-
Apr 23rd, 2002, 12:23 PM
#6
Thread Starter
New Member
Hi again Arc,
I just finished testing out the code... it works great!!! Many thanks!
One more thing, my listbox has a listcount of 53, and the itemdata property is zero-based. So I'm having trouble because in order to get to the first item the user must press "00" instead of "01". Also I'm having trouble with the validation of the numbers. How would I validate the keypress event so that the user does not enter a number that is "53" (because of it being zero-based) and above???
Thanks again for all your help!!!
-
Apr 23rd, 2002, 12:38 PM
#7
PowerPoster
this should work. It goes from 01 to 53 and displays a messagebox if the user goes over 53.
VB Code:
Private Sub List1_KeyPress(KeyAscii As Integer)
Static Pressed As Integer, MoveToChr As Integer
On Error Resume Next
Pressed = Pressed + 1
If Pressed = 2 Then
MoveToChr = MoveToChr & Chr(KeyAscii)
Else
MoveToChr = Chr(KeyAscii)
Exit Sub
End If
Pressed = 0
MoveToChr = MoveToChr - 1
If MoveToChr > 52 Then
MsgBox "Index's above 53 not allowed"
Exit Sub
End If
List1.ListIndex = MoveToChr
List1.Selected(MoveToChr) = False
End Sub
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|