|
-
Sep 20th, 2000, 04:37 PM
#1
Thread Starter
Hyperactive Member
put code similar to the following in your keyup event... KeyCode is a default parameter of the keyup event that keeps track of the key number of each key on your keyboard.
Code:
If KeyCode = 38 then ' up key hit
'enter code to move bar up
text1.setfocus ' return focus to text box
End if
If KeyCode = 40 then ' down key hit
'enter code to move bar down
text1.setfocus ' return focus to text box
End If
If KeyCode = 33 then ' pg up hit
'enter code to move bar to top
text1.setfocus ' return focus to text box
End If
If KeyCode = 34 then ' pg down hit
'enter code to move bar to bottom
text1.setfocus ' return focus to text box
End If
A good way to know the keycode of the keys on your keyboard is to place a MsgBox(KeyCode) line in the event to display the number for each key pressed. Then you code in what you want it to do when you know the key number.
[Edited by scuzymoto on 09-20-2000 at 05:39 PM]
-
Sep 22nd, 2000, 01:47 AM
#2
New Member
Hmmmm. What do I do wrong?
When I try what you wrote, Scuzymoto, it doesn't work. Probably the code I place on your quote "enter code to move bar up" is not correct.
Code:
private sub txtSearch_Keydown (Keycode as ...)
If KeyCode = 38 then ' up key hit
'enter code to move bar up
lvCustomers.setfocus
sendkeys Keycode
txtSearch.setfocus ' return focus to text box
End if
End Sub
When I look in the listview to see when keycode is sended, it looks to be changed. But more even important...It won't work!
Can I do it a totaly different way? Like with the API call SendMessage?
[Edited by palinden on 09-22-2000 at 02:59 AM]
-
Sep 22nd, 2000, 03:56 AM
#3
Lively Member
Palinden, you don't need to use sendkey, use this code at the place
Code:
Private Sub txtSearch_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 38 Then ' up key hit
'code to move up
If lvCustomers.ListIndex > 0 Then
Me.lvCustomers.ListIndex = Me.lvCustomers.ListIndex - 1
End If
txtSearch.SetFocus ' return focus to text box
End If
If KeyCode = 40 Then ' down key hit
'code to move down
If Me.lvCustomers.ListIndex < Me.lvCustomers.ListCount - 1 Then
Me.lvCustomers.ListIndex = Me.lvCustomers.ListIndex + 1
End If
txtSearch.SetFocus ' return focus to text box
End If
If KeyCode = 33 Then ' pg up hit
'code to move to top
Me.lvCustomers.ListIndex = 0
Me.txtSearch.SetFocus ' return focus to text box
End If
If KeyCode = 34 Then ' pg down hit
'code to move to bottom
Me.lvCustomers.ListIndex = Me.lvCustomers.ListCount - 1
txtSearch.SetFocus ' return focus to text box
End If
End Sub
-
Sep 22nd, 2000, 10:57 AM
#4
Thread Starter
Hyperactive Member
KWell's code is how I would do it too.
-
Sep 25th, 2000, 04:57 AM
#5
New Member
Hmmmm...
There must be something wrong. My listview doesn't have the listindex property.
Code:
If KeyCode = 38 Then ' up key hit
'code to move up
If lvCustomers.ListIndex > 0 Then
Me.lvCustomers.ListIndex = Me.lvCustomers.ListIndex - 1
End If
txtSearch.SetFocus ' return focus to text box
End If
Now what? Drop the listview and thy something else?
ps. I'm using VB6
-
Sep 25th, 2000, 11:17 AM
#6
Thread Starter
Hyperactive Member
Not sure what to tell you... It took me 5 minutes to create a form with a text box called txtSearch and a list box called lvCustomers. I then placed 6 names in the customer list and pasted the code that Paliden posted above as the only code in the project. It worked perfectly for me. You might try doing what I just did (it works) and then decide what is different about the code in your project. If you listbox doesn't have a listindex property maybe your using an obscure listbox. Make sure to use the default listbox that is in your components list when you first start a project. Good luck.
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
|