Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wierd ComboBox behaviour... bug? 1

Status
Not open for further replies.

msc0tt

IS-IT--Management
Jun 25, 2002
281
0
0
CA
I've got a combobox. When it gets focus, I populate it programically, set the .ListIndex to 0 to ensure the 1st item is selected, then drop the box with a call to SendMessage. All looks and works well.

Here's the bug:
If I click the mouse to another control before any other action, the combobox scrolls up, with the control displaying NOTHING in its field, and the combobox retains focus. I second click outside the control releases focus, but the .ListIndex is now -1! (indicating no selection in the combobox).
Anyone know how I can avoid this?? I don't mind the two clicks to move focus, but I need the currently selected item in the combobox to remain the current item!
-with thanks,
Mike
 
i think this is a standard thing with combobox, try it yourself, if nothing is selected (ie clicking of the combo) it reverts to the last known listindex (in your case 0, change the list index to a diff value to see if that retains that value)
if you click away you are just closing the combo box dropdown not passing focus.(i think)

i hope i made sense there, if not sorry to confuse!! If somethings hard to do, its not worth doing - Homer Simpson
 
How 'bout posting a SendKey, like {"Tab"} to force the focus to shift to the next tab indexed item? You could put this either where you accept the combo box input or in a key event. Just a thought...

An example I used [not with a combo, though :-( ]

'data input check - only allows integers
Private Sub txtCycleLogCount_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Is < 32 'control keys
'user hit ENTER
If KeyAscii = 13 Then SendKeys &quot;{Tab}&quot;
Case 48 To 57 'detected digit - ok
Case Else 'reject all other keys
KeyAscii = 0
End Select
End Sub
 
What you say would make sense if I hadn't selected an item. But I do, at the end of my combo_GotFocus() routine (combo.ListIndex = 0). It even displays with the dotted box around the first entry to indicate it was selected. I guess the question is whether the combobox is *supposed* to reset the .ListIndex if it loses focus in certain ways?
 
The Doctor comes through!!
This reversal of events solved the issue!
-many thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top