Results 1 to 6 of 6

Thread: Moving cursor within a combo box

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    88

    Moving cursor within a combo box

    Hello. I have a VB6 app that, when a user opens a form the focus is on a drop-down. If they hit the space bar (an invalid entry) it slaps their hand with a message box and makes them re-enter. The only problem is that once the message box closes the cursor is in the second position within the combo box. I'm still looking, but I'm not finding how to reset the cursor to the first position.

    Thanks!

    Ed

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    VB Code:
    1. Combo1.SelStart = 0

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    88
    Thank you! But, I must be doing something wrong... here's how I integrated the line above:

    VB Code:
    1. If KeyAscii = 32 Then
    2.         MsgBox ("Cannot begin search with a space")
    3.         Me.cboChooseHospital.SelStart = 0
    4.         Exit Sub
    5. End If

    After the msgbox is cleared, the cursor stays in the second position. Should the SelStart be in a sub procedure?!

    Thank you for your quick response!!!

    Ed

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Try this :

    VB Code:
    1. If KeyAscii = 32 Then
    2.         MsgBox ("Cannot begin search with a space")
    3.         KeyAscii = 0
    4.         Me.cmbHospital.SelStart = 0
    5.         Exit Sub
    6. End If


    Has someone helped you? Then you can Rate their helpful post.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    88
    Whoo Hooo! That's it!! ¡Buenísimo!

    Now the cursor goes right back to the initial position!!

    Thanks everyone for your help!!!

    Ed

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    yeah i was puzzled for a min.. then remembered that it doesn't actually send the key to the control until the sub ends...

    on a side note... it isn't really the best idea to pop up a message box when a user hits a space.. it is better to

    1) do it on the lost focus event of the control
    2) manually remove any spaces the user does enter
    3) do it how you have it now.. but without the msgbox

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