Results 1 to 19 of 19

Thread: After form load, Combo Box is highlighted

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    126

    After form load, Combo Box is highlighted

    Code:
     For b = 1 To Me.TOTResetSet(a).ListCount
            If Me.TOTResetSet(a).ItemData(b - 1) = Val(Ram_TOTReset(a)) Then
                Me.TOTResetSet(a).ListIndex = b - 1
                Exit For
            End If
        Next b
    When the above loads (form_load), the Combo Dropdown is highlighted as per the attached screencap. How can I prevent this from happening? As you can see, there are other Combo Boxes as well but this is the only one that behaves this way
    Attached Images Attached Images  

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: After form load, Combo Box is highlighted

    What is the TabIndex value of that ComboBox? The default behavior is that the control that can get focus that has the smallest TabIndex value starts out with focus.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    126

    Re: After form load, Combo Box is highlighted

    It doesn't have the lowest TabIndex value. Indeed, other combo boxes on that tab do but only this one highlights on load

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    126

    Re: After form load, Combo Box is highlighted

    So I renumbered the TabIndex all the objects and made sure the TOT Reset field didn't have it. The result is that the cursor is placed in the lowest number TabIndex field but the highlighting remains as per my screencap.

    Frustrating!

  5. #5
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: After form load, Combo Box is highlighted

    What ComboBox control are you using? I tried to recreate the problem with an standard VB ComboBox but it worked fine.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    126

    Re: After form load, Combo Box is highlighted

    Quote Originally Posted by Eduardo- View Post
    What ComboBox control are you using? I tried to recreate the problem with an standard VB ComboBox but it worked fine.
    Standard VB6 ones
    Attached Images Attached Images  

  7. #7
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: After form load, Combo Box is highlighted

    What style is the ComboBox?

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    126

    Re: After form load, Combo Box is highlighted

    Dropdown Combo
    Last edited by KenHorse; Nov 21st, 2020 at 06:06 PM.

  9. #9
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: After form load, Combo Box is highlighted

    And when you change it to ComboList type?

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: After form load, Combo Box is highlighted

    if you do not run the combobox code in form load does it still highlight?
    as you have made a selection of combobox items in your code it would be normal behavior
    you can resolve by putting Combo1.SelLength = 0, similar or setfocus to any other control in the form activate event
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: After form load, Combo Box is highlighted

    I would suspect some code that is running upon form load as the culprit here.

  12. #12
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: After form load, Combo Box is highlighted

    Quote Originally Posted by Arnoutdv View Post
    What style is the ComboBox?
    It seems that this is default-behaviour (happens also with Krools ComboBoxW in that style).

    And what was suggested already by westconn1 (resetting the SelLenght in Form_Load),
    is IMO the easiest way to solve this.

    Olaf

  13. #13
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: After form load, Combo Box is highlighted

    resetting the SelLenght in Form_Load
    doesn't actually work in form_load, must be activate
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  14. #14
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,121

    Re: After form load, Combo Box is highlighted

    Quote Originally Posted by Schmidt View Post
    It seems that this is default-behaviour (happens also with Krools ComboBoxW in that style).
    This is a *bug* in the built-in Windows combobox control and here is a repro: Add a CommandButton1 and Combo1 (in that order) and use this snippet

    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Combo1.AddItem "test"
        Combo1.AddItem Now
        Combo1.ListIndex = Combo1.ListCount - 1
        Combo1.Width = Combo1.Width + 100
    End Sub
    It's the resize event that trips the control to incorrectly highlight the text even when the control is *not* focused which looks very weird with multiple combos on the form (all of them stay selected).

    Tabbing in and out of the control clears the repaint issues. Have not found a way to prevent/redraw programatically when this happens though didn't try very hard.

    Edit: Setting Combo1.SelLength = 0 after resizing seems to fix it with no side-effects at first glance.

    cheers,
    </wqw>

  15. #15
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: After form load, Combo Box is highlighted

    I've had this problem before too. When a ComboBox has TabIndex=0, there can be problems. I've solve it by always making all the ComboBoxes have non-zero TabIndex. I do that in one of two ways: 1) just re-arrange the form so that the ComboBox isn't first, or 2) Put a "hidden" TextBox on the form that's got the TabIndex=0. I don't exactly mean Visible=False. Rather, I mean off to the left of the form (negative Left value) but still Visible=True. That way, when the form loads, that "hidden" TextBox has the focus, and my ComboBoxes work as they should.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    126

    Re: After form load, Combo Box is highlighted

    Quote Originally Posted by wqweto View Post
    This is a *bug* in the built-in Windows combobox control and here is a repro: Add a CommandButton1 and Combo1 (in that order) and use this snippet

    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Combo1.AddItem "test"
        Combo1.AddItem Now
        Combo1.ListIndex = Combo1.ListCount - 1
        Combo1.Width = Combo1.Width + 100
    End Sub
    It's the resize event that trips the control to incorrectly highlight the text even when the control is *not* focused which looks very weird with multiple combos on the form (all of them stay selected).

    Tabbing in and out of the control clears the repaint issues. Have not found a way to prevent/redraw programatically when this happens though didn't try very hard.

    Edit: Setting Combo1.SelLength = 0 after resizing seems to fix it with no side-effects at first glance.

    cheers,
    </wqw>
    Actually (as shown in my screencap) only that one ComboBox highlights even though there are several others on the form. I tried the Combo1.SelLength = 0 thing and it works on initial form_load. But when I change tabs, that ComboBox highlights again.

    Frustrating!

  17. #17
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,121

    Re: After form load, Combo Box is highlighted

    Quote Originally Posted by KenHorse View Post
    But when I change tabs, that ComboBox highlights again.
    When you manipulate ListIndex *and* resize the control (set Width property or call Move method) the bug is manifested.

    I just fixed it in a custom multi-column combobox control of mine with something like this:

    Code:
        Case WM_WINDOWPOSCHANGED
            If Not m_bFocused Then
                frWndProcCombo = CallNextWndProc(m_uSubclassCombo, hWnd, wMsg, wParam, lParam)
                SelLength = 0
                Exit Function
            End If
    . . . in the wndproc. This just resets SelLength upon resizing only if the control is *not* focused.

    There is no problem with focused comboboxes and there is no problem if after setting ListIndex the control is not resized.

    To trigger this repaint bug on an unfocused combobox both ListIndex must be set and immediately after that the control must be resized.

    cheers,
    </wqw>

  18. #18
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: After form load, Combo Box is highlighted

    You can position a textbox's Left to say -999 and arrange for it to have the focus after form loads.

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    126

    Re: After form load, Combo Box is highlighted

    I finally solved my problem by setting the SelLength property to 0 in the SSTab sub, so whenever a different tab is selected, SelLength is reset.

    Thanks to all who responded!

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