Results 1 to 6 of 6

Thread: How to send cursorkey to listview

  1. #1

    Thread Starter
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316
    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]
    SCUZ

  2. #2
    New Member
    Join Date
    Sep 2000
    Location
    Netherlands
    Posts
    10

    Unhappy

    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]

  3. #3
    Lively Member
    Join Date
    Jun 2000
    Location
    Belgium
    Posts
    77
    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
    KWell

  4. #4

    Thread Starter
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316
    KWell's code is how I would do it too.
    SCUZ

  5. #5
    New Member
    Join Date
    Sep 2000
    Location
    Netherlands
    Posts
    10

    Unhappy

    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

  6. #6

    Thread Starter
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316
    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.
    SCUZ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width