Results 1 to 19 of 19

Thread: Focus problem

  1. #1

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Focus problem

    I have a treeview and then an array of pictureboxes.
    On picHolder(1) I have an array of textboxes.

    In the treeview click code I have the following:
    Code:
    picHolder(1).ZOrder 0
    txtAdd(0).SetFocus
    cmbGrade.ListIndex = 0
    optGender(0).Value = True
    When txtAdd(0) has focus the backcolor changes to a light grey colour.
    When txtAdd(0) loses focus the backcolor changes to white.

    When I click on the treeview this code fires, the txtAdd(0) backcolor changes, but the cursor is not in the textbox.
    If I hit the tab key all the textboxes loses focus, but the backcolor stays grey, it goes somewhere, and the second time I hit the tab key the focus is back on txtAdd(0) with the cursor, and then goes through the textboxes as expected.

    The treeview tabindex = 0 and the txtAdd(0) tabindex = 1

    Anybody got any suggestions why?

    Also, why I am on it, are pictureboxes the best way to do this, show different sets of controls?
    I think I read somewhere that controls inside of frames have a problem with the resize code. Is this correct?

    Thanks
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  2. #2
    Lively Member astroanu2004's Avatar
    Join Date
    Jan 2008
    Location
    Sri Lanka
    Posts
    108

    Re: Focus problem

    i have encountered something similer
    my suggetion i not to use zorder
    i normaly use the visible property
    althou it takes alot of lines its easy
    can somebody tell me a different way ill accept

  3. #3

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Focus problem

    Thanks astroanu2004 but this didn't make any difference.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Focus problem

    Quote Originally Posted by aikidokid
    I have a treeview and then an array of pictureboxes.
    On picHolder(1) I have an array of textboxes.

    In the treeview click code I have the following:
    Code:
    picHolder(1).ZOrder 0
    txtAdd(0).SetFocus
    cmbGrade.ListIndex = 0
    optGender(0).Value = True
    When txtAdd(0) has focus the backcolor changes to a light grey colour.
    When txtAdd(0) loses focus the backcolor changes to white.

    When I click on the treeview this code fires, the txtAdd(0) backcolor changes, but the cursor is not in the textbox.
    If I hit the tab key all the textboxes loses focus, but the backcolor stays grey, it goes somewhere, and the second time I hit the tab key the focus is back on txtAdd(0) with the cursor, and then goes through the textboxes as expected.

    The treeview tabindex = 0 and the txtAdd(0) tabindex = 1

    Anybody got any suggestions why?

    Also, why I am on it, are pictureboxes the best way to do this, show different sets of controls?
    I think I read somewhere that controls inside of frames have a problem with the resize code. Is this correct?

    Thanks
    You've told us what happens, but what do you want to have happen? In other words what is the problem?

    As far as using pictureboxes as a container for other controls I suppose that's okay, but the normal way is to use frames. And I don't think controls inside a frame will be any more of a problem to resize than those in a picture. How are you doing the resizing?

  5. #5

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Focus problem

    Quote Originally Posted by Martin
    You've told us what happens, but what do you want to have happen? In other words what is the problem?
    The problem is that, although the backcolor is changed, which shows that the GotFocus event is firing, the textbox doesn't seem to have the focus, as the cursor is not in the textbox, and you need to press the tab key twice to get it in there.

    Quote Originally Posted by Martin
    As far as using pictureboxes as a container for other controls I suppose that's okay, but the normal way is to use frames. And I don't think controls inside a frame will be any more of a problem to resize than those in a picture. How are you doing the resizing?
    I haven't started the resize code yet. This was just something I though I had read here somewhere
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Focus problem

    Try this instead.

    Code:
    picHolder(1).ZOrder 0
    cmbGrade.ListIndex = 0
    optGender(0).Value = True
    txtAdd(0).SetFocus
    BTW did you create another thread where I suggested you use the Visible property of the picture boxes rather than ZOrder? If so, just out of curiosity, why did you make that choice?

  7. #7

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Focus problem

    Quote Originally Posted by MartinLiss
    Try this instead.
    No, still have to hit the tab twice to get the cursor into the txtAdd(0)

    Quote Originally Posted by MartinLiss
    BTW did you create another thread where I suggested you use the Visible property of the picture boxes rather than ZOrder? If so, just out of curiosity, why did you make that choice?
    No it wasn't me. Maybe the op in post #2 of this thread.

    Would you suggest the visible property be the way to go indtead of the zorder?
    If so, just out of curiosity, what are the merits of this way?
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  8. #8

  9. #9

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Focus problem

    I will change the zorder to visible and see if this makes a difference. If not I will post the project in a minute. Thanks
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  10. #10

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Focus problem

    I have used a couple of controls from the vbAccelerator site in this project, so you may have a problem running it.
    They are the treeview and the image list.

    I have changed it as suggested, but I still get the error.!

    To get this problem, when running in IDE, select "Membership" from the treeview, then select "Add New Member".
    You will see that the textbox is highlighted, but the focus isn't there until you press the tab key for the second time.

    Thanks for the help
    Last edited by aikidokid; Jan 18th, 2008 at 03:53 PM.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Focus problem

    Since the Treeview is vbAccerator's I can't run the project but maybe I can still help. First, put something like the following in the GotFocus event of txtAdd.

    Code:
    If Index = 0 Then
        Debug.Print "I got the focus"
    End If
    If that shows that it does get focus (and I assume it will), then put a breakpoint in the LostFocus event and see if the stack will show you how you got there. If it doesn't supply enough info then there's something else we can try.

  12. #12

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Focus problem

    Now thats interesting.
    If I add debug.print it prints to the immediate window, but still the error.
    If I add a msgbox, it displays the msgbox and then when I close it the txtAdd(0) has the focus!

    Don't know if that gives you any more of a clue!!
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  13. #13

  14. #14

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Focus problem

    It doesn't get to the breakpoint at the lostfocus event??
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  15. #15

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Focus problem

    Quote Originally Posted by MartinLiss
    Replace the Msgbox with DoEvents and see what happens.
    No still the same.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  16. #16

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Focus problem

    This is my code below:

    Treeview code:
    Code:
        Select Case strChildNode
            Case "0-"
                'Membership
                Select Case strGrandChildNode
                    Case "0"
                        '\\Add new
                        picHolder(1).Visible = True
                        cmdAdd.Caption = "&Add Member"
                        Call cmdCancel_Click
                        cmbGrade.ListIndex = 0
                        optGender(0).Value = True
                        lvwMain.Visible = False
                        txtAdd(0).SetFocus
                        lngLastHolder = 1
    Textbox code:
    Code:
    Private Sub txtAdd_GotFocus(Index As Integer)
    On Error GoTo ErrTrap
    Dim i As Long
    
    Select Case Index
        Case 0 To 9
            For i = 0 To 18
                If i = Index Then
                    DoEvents
                    lblAdd(Index).FontBold = True
                    txtAdd(Index).BackColor = &H80000016
                Else
                    lblAdd(i).FontBold = False
                    If i < 13 Then txtAdd(i).BackColor = vbWhite
                End If
            Next i
        Case 10, 11
            For i = 0 To 18
                If i = Index + 5 Then
                    lblAdd(Index + 5).FontBold = True
                    txtAdd(Index).BackColor = &H80000016
                Else
                    lblAdd(i).FontBold = False
                    If i < 13 Then txtAdd(i).BackColor = vbWhite
                End If
            Next i
        Case 12
            For i = 0 To 18
                If i = Index + 6 Then
                    lblAdd(Index + 6).FontBold = True
                    txtAdd(Index).BackColor = &H80000016
                Else
                    lblAdd(i).FontBold = False
                    If i < 13 Then txtAdd(i).BackColor = vbWhite
                End If
            Next i
    End Select
    
    Exit Sub
    Code:
    Private Sub txtAdd_LostFocus(Index As Integer)
    On Error GoTo ErrTrap
    
    'capitalise first letter
    Select Case Index
        Case 0 To 5
            txtAdd(Index).Text = StrConv(txtAdd(Index).Text, vbProperCase)
        Case 7 To 12
            txtAdd(Index).Text = StrConv(txtAdd(Index).Text, vbProperCase)
    End Select
    
    If Index <> 0 Then
        Dim i As Long
        For i = 0 To 12
            txtAdd(i).BackColor = vbWhite
            lblAdd(i).FontBold = False
        Next i
    End If
    
    Exit Sub
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  17. #17

  18. #18

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Focus problem

    Quote Originally Posted by MartinLiss
    Okay last idea...

    At the very end of txtAdd_GotFocus put

    txtAdd(Index).SetFocus
    That now gives it the focus as I wanted, but ......
    When I tab to go to the next text box, the focus dissapears and then after the second tab it goes back to txtAdd(0) and after that it tabs through as expected.

    Thanks for your help anyway Martin, it's much appreciated (and rated).

    I will leave the thread open in case anybody else can come up with anything.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  19. #19

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Focus problem

    It seems like this is something to do with the vbAccelerator treeview, as I have replaced with the VB treeview and the problem doesn't exist.

    That said, if anybody has a solution to this I would be interested as the VBA control has a lot of nice features.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

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