Results 1 to 11 of 11

Thread: Control tab order - initial focus problem

  1. #1

    Thread Starter
    Member McBain2's Avatar
    Join Date
    Sep 2003
    Location
    UK, Glos.
    Posts
    60

    Angry Control tab order - initial focus problem

    Ok, there has got to be a simple solutions to this but I can't find it...

    With newly created forms with .NET, how on earth do I select which control is to have the focus by default???
    With VB 6 it used to be a simple case of setting the tab order - the first in order would have the focus when the form loaded.
    With .NET however, this is no longer true - and even using a SetFocus command on the Load and Activated events will not shift the focus.

    This is most irtritating since I have created a logon box but the password textbox simply will not have focus when it loads up resulting in an awkward user interface.

    Any ideas / solutions most welcome...

    Thanks in advance!

  2. #2
    Member
    Join Date
    Oct 2002
    Location
    la la la you can't see me
    Posts
    46
    As long as you make sure that you re-number every control, start at zero, and don't duplicate or skip numbers, it should work fine by changing the tab index. I just tested on mine, it worked.
    What does "formatting drive C..." mean?!

  3. #3

    Thread Starter
    Member McBain2's Avatar
    Join Date
    Sep 2003
    Location
    UK, Glos.
    Posts
    60
    Yep, tried all that... there are a total of 7 controls on this form, a title label, a label and textbox for the user id and password and ok and cancel buttons.
    I have set the tab order starting from zero at the password textbox and stepped up 1 for all other controls... still doesn't work.
    Nothing seems to have the focus to start with, then I press tab once and I'm on the password text box?

    Stranger still, it works fine on another form - a properties window - the focus starts with the first item in the tab order, even when I change it!


    Arrrgggghhh!

  4. #4
    Member
    Join Date
    Oct 2002
    Location
    la la la you can't see me
    Posts
    46
    what order do you have the tabs set in?
    What does "formatting drive C..." mean?!

  5. #5

    Thread Starter
    Member McBain2's Avatar
    Join Date
    Sep 2003
    Location
    UK, Glos.
    Posts
    60
    Tab order on the logon form is... (no other controls on the form)

    Control - Tab Index
    lblHeader - 4
    lblUserID - 5
    txtUserID - 6
    lblPassword - 0
    txtPassword - 1 -should thus have focus be default!
    btnOK - 2
    btnCancel - 3

    Starts up and nothing visibly has focus until I press the tab key - at which point txtPassword has the focus.
    lblPassword has to be 0 (before txtPassword) in order for the keyboard shortcut to work.

    My other properties form works fine, i.e. tab order starts lblUserID as 0 and txtUserID as 1. Load the form and txtUser has the focus straight away! Then if I change the tab order, the default focused control also changes - as you would expect! So....???!!!

    Why!!! What??? I must be missing something silly here!?!?

  6. #6
    Addicted Member The Phoenix's Avatar
    Join Date
    Aug 2003
    Location
    With my wife
    Posts
    142
    If you want to force focus on a control, just use the Form Load event.
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         txtPassword.focus()
    3.     End Sub

    That should do exactly what you want.

    Of course, I'm not sure how the tab order would work with that. I think that if you hit "Tab" it would go on to the next sontrol like it should, but I'm not sure.
    Take my love
    Take my land
    Take me where I cannot stand
    I don't care, I'm still free
    You can't take the sky from me...

  7. #7

    Thread Starter
    Member McBain2's Avatar
    Join Date
    Sep 2003
    Location
    UK, Glos.
    Posts
    60
    Nope, tried that! And setting the focus on the Activated event too - but still nothing has the focus until I hit the tab key!

    Bizarre!


    I've attached the source code for this form. If anyone can point out my deliberate mistake, I'd be most grateful!!!
    Attached Files Attached Files

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Is it a normal textbox? Or a maskedit or something?

    Maybe try deleting the textbox and recreating it.

  9. #9

    Thread Starter
    Member McBain2's Avatar
    Join Date
    Sep 2003
    Location
    UK, Glos.
    Posts
    60
    Yep, is a normal textbox - although it does use a password char, but then I've tried it without that too.
    Form is a Fixed dialog, but have changed that too.
    Dunno... have tried re-creating all the controls, no luck.
    Will try recreating the entire form I guess...

    Strange, very strange!

  10. #10
    Member
    Join Date
    May 2003
    Posts
    41
    I had the same problem to. I tried to set the focus to a control on load but it wouldn't do it. I was able to set the focus to the control with form activated. I know this may not answer your question, as I wish someone could tell me why it doesn't work. But if you need a quick fix try what I did. Let me know if it works for you also.

    Thanks,
    Tomson

  11. #11
    Junior Member
    Join Date
    Feb 2004
    Location
    Cape Town, South Africa
    Posts
    18
    This only happens in VS.net 2002, it is fixed in vs.net 2003.

    Took me a few days to discover !!

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