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
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.
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.
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
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
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>
Last edited by wqweto; Nov 22nd, 2020 at 05:07 AM.
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.
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.
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.