ComboBox Bug??: Click Arrow, ListIndex = -1... Regardless of ACTUAL LIST INDEX??? 
Author Message
 ComboBox Bug??: Click Arrow, ListIndex = -1... Regardless of ACTUAL LIST INDEX???

Now wait a minute, is this a VB6 ComboBox BUG:

For reasons there is no need to go into here, I need to capture the
ListIndex of a ComboBox on a form as soon as that ComboBox gets the
Focus.  (FWIW, I later compare that value to the value of the ComboBox
after my user has triggered the ComboBox's Click or LostFocus event).

But, guess what....

I get a RELIABLE reading of the current ListIndex only if my user
"enters" the ComboBox by clicking on the *textbox* portion of the
ComboBox!  If my user clicks on the *dropdown arrow* portion of the
ComboBox, I often get a ListIndex reading of "-1"... even if that's
NOT the current ListIndex of the ComboBox!!!

Interestingly, this appears to be a momentary bug/state of affairs.
In testing, I put this in my code:

Debug.Print "Current List Index:  " & MyComboBox.ListIndex

...And then put a Breakpoint just after this line, the Debug.Print
produces the following *immediate* results:

"Current ListIndex:  -1"

...in the Immediate Window.  But, guess what?  If I keep my code
stalled on that Breakpoint, and then use the Immediate Window to test
the ListIndex value of my ComboBox... I'll get the CORRECT LISTINDEX!

My (perhaps naive) conclusion is that clicking on the Arrow portion of
a VB6 ComboBox causes the ComboBox's ListIndex to MOMENTARILY be "-1";
regardless of what the current ListIndex actually is.

Have any of you experienced this?  And, considering what I'm trying to
achieve... do any of you have any idea how I'd work around this issue?
Thanks in advance.



Mon, 08 Dec 2003 07:17:34 GMT  
 ComboBox Bug??: Click Arrow, ListIndex = -1... Regardless of ACTUAL LIST INDEX???
Using the code below, I couldn't reproduce your results.. always correct.

Form with Command button (TabIndex = 0) and a combobox
'=============
Option Explicit

Private Sub Form_Load()
   With Combo1
      .AddItem "Item " & .ListCount + 1
      .AddItem "Item " & .ListCount + 1
      .AddItem "Item " & .ListCount + 1
      .AddItem "Item " & .ListCount + 1
      '.ListIndex = 0
   End With
End Sub

Private Sub Combo1_GotFocus()
   Debug.Print Combo1.ListIndex
End Sub

'=============


Quote:
> Now wait a minute, is this a VB6 ComboBox BUG:

> For reasons there is no need to go into here, I need to capture the
> ListIndex of a ComboBox on a form as soon as that ComboBox gets the
> Focus.  (FWIW, I later compare that value to the value of the ComboBox
> after my user has triggered the ComboBox's Click or LostFocus event).

> But, guess what....

> I get a RELIABLE reading of the current ListIndex only if my user
> "enters" the ComboBox by clicking on the *textbox* portion of the
> ComboBox!  If my user clicks on the *dropdown arrow* portion of the
> ComboBox, I often get a ListIndex reading of "-1"... even if that's
> NOT the current ListIndex of the ComboBox!!!

> Interestingly, this appears to be a momentary bug/state of affairs.
> In testing, I put this in my code:

> Debug.Print "Current List Index:  " & MyComboBox.ListIndex

> ...And then put a Breakpoint just after this line, the Debug.Print
> produces the following *immediate* results:

> "Current ListIndex:  -1"

> ...in the Immediate Window.  But, guess what?  If I keep my code
> stalled on that Breakpoint, and then use the Immediate Window to test
> the ListIndex value of my ComboBox... I'll get the CORRECT LISTINDEX!

> My (perhaps naive) conclusion is that clicking on the Arrow portion of
> a VB6 ComboBox causes the ComboBox's ListIndex to MOMENTARILY be "-1";
> regardless of what the current ListIndex actually is.

> Have any of you experienced this?  And, considering what I'm trying to
> achieve... do any of you have any idea how I'd work around this issue?
> Thanks in advance.



Mon, 08 Dec 2003 07:24:50 GMT  
 ComboBox Bug??: Click Arrow, ListIndex = -1... Regardless of ACTUAL LIST INDEX???
It looks like this only occurs with comobox stlyle = 0-DropDown Combo. And
it looks like a DoEvents in the combo's DropDown event will solve the
problem.

Private Sub Combo1_DropDown()
   DoEvents
End Sub

Private Sub Combo1_GotFocus()
   Debug.Print Combo1.ListIndex
End Sub

David


Quote:
> Now wait a minute, is this a VB6 ComboBox BUG:

> For reasons there is no need to go into here, I need to capture the
> ListIndex of a ComboBox on a form as soon as that ComboBox gets the
> Focus.  (FWIW, I later compare that value to the value of the ComboBox
> after my user has triggered the ComboBox's Click or LostFocus event).

> But, guess what....

> I get a RELIABLE reading of the current ListIndex only if my user
> "enters" the ComboBox by clicking on the *textbox* portion of the
> ComboBox!  If my user clicks on the *dropdown arrow* portion of the
> ComboBox, I often get a ListIndex reading of "-1"... even if that's
> NOT the current ListIndex of the ComboBox!!!

> Interestingly, this appears to be a momentary bug/state of affairs.
> In testing, I put this in my code:

> Debug.Print "Current List Index:  " & MyComboBox.ListIndex

> ...And then put a Breakpoint just after this line, the Debug.Print
> produces the following *immediate* results:

> "Current ListIndex:  -1"

> ...in the Immediate Window.  But, guess what?  If I keep my code
> stalled on that Breakpoint, and then use the Immediate Window to test
> the ListIndex value of my ComboBox... I'll get the CORRECT LISTINDEX!

> My (perhaps naive) conclusion is that clicking on the Arrow portion of
> a VB6 ComboBox causes the ComboBox's ListIndex to MOMENTARILY be "-1";
> regardless of what the current ListIndex actually is.

> Have any of you experienced this?  And, considering what I'm trying to
> achieve... do any of you have any idea how I'd work around this issue?
> Thanks in advance.



Mon, 08 Dec 2003 12:27:52 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Combobox Click Event from Arrow

2. VB6: ComboBox with .Style Dropdown List not maintaining .ListIndex setting

3. Clicking outside combobox trigger the combobox click event

4. up arrow, down arrow, left arrow, right arrow

5. Combobox click erroneously increments to next list item.

6. Right-Click on ComboBox List Portion

7. ComboBox listindex????

8. listindex property for combobox

9. VB5 ComboBox ListIndex appears to become reset to zero

10. Combobox & Listindex

11. Combobox Listindex problem

12. combobox, listindex, & populate text

 

 
Powered by phpBB® Forum Software