Setting Combo box ListIndex initiates Combo box Click event 
Author Message
 Setting Combo box ListIndex initiates Combo box Click event

Hi,

   I'm debugging a predecessor's VB4 code.  A combo box's ListIndex is
set while in a For Loop.  After (successfully) setting the ListIndex,
the program jumps to the click event for that combo box - without
finishing the For Loop.

   Would someone confirm that this is NOT designed (i.e. VB4 does not
routinely start a click event for a combo box when its ListIndex is
set)?

Thanks,

Maribeth

relevant snippets for sorted combo box, ToolName(I)...

Sub InitComboBoxes()
  Dim I As Integer
  Dim J As Integer
  {various DB declarations - DB filling works correctly}
  Dim TempToolVar As String
 .
 .
  For I = 1 to 8     'there are 8 combo boxes
     frmTool.ToolName(I).Clear
     frmTool.ToolName(I).AddItem "[none]"
     frmTool.ToolName(I).Enabled = False
     .
     .
  Next I
.
.
  frmTool.ToolName(1).Enabled = True
.
.
  'following fills the 8 combo boxes correctly
 ToolSet.MoveFirst
  Do Until ToolSet.EOF
    TempToolVar = ToolSet.Fields("ToolName").Value
    For I = 1 to 8    
      frmTool.ToolName(I).AddItem TempToolVar
    Next I
    ToolSet.MoveNext
  Loop

  'offending code - when GToolName(I) is not none....
  For I = 1 to 8
    If GToolName(I) <> "[none]" Then  'GToolName is a global variable
     For J = 0 To frmTool.ToolName(I).ListCount - 1
        If frmTool.ToolName(I).List(J) = GToolName(I) Then
'The following line executes then jumps to the ToolName Click event
          frmTool.ToolName(I).ListIndex = J
        End if
     Next J
    Else
     frmTool.ToolName(I).ListIndex = frmTool.ToolName(I).ListCount - 1
    End If
  Next I

End Sub



Sun, 03 Jun 2001 03:00:00 GMT  
 Setting Combo box ListIndex initiates Combo box Click event
Sorry, but this action certainly is "by design".  VB fires a click event
everytime ListIndex is set in code IF setting it changes the ListIndex from
what it was.  For example, if the .ListIndex is 4, and you execute

        Combo1.ListIndex = 4

a click event does not fire.

Lee Weiner
weiner AT fuse DOT net


Quote:

>Hi,

>   I'm debugging a predecessor's VB4 code.  A combo box's ListIndex is
>set while in a For Loop.  After (successfully) setting the ListIndex,
>the program jumps to the click event for that combo box - without
>finishing the For Loop.

>   Would someone confirm that this is NOT designed (i.e. VB4 does not
>routinely start a click event for a combo box when its ListIndex is
>set)?

>Thanks,

>Maribeth

>relevant snippets for sorted combo box, ToolName(I)...

>Sub InitComboBoxes()
>  Dim I As Integer
>  Dim J As Integer
>  {various DB declarations - DB filling works correctly}
>  Dim TempToolVar As String
> .
> .
>  For I = 1 to 8     'there are 8 combo boxes
>     frmTool.ToolName(I).Clear
>     frmTool.ToolName(I).AddItem "[none]"
>     frmTool.ToolName(I).Enabled = False
>     .
>     .
>  Next I
>..
>..
>  frmTool.ToolName(1).Enabled = True
>..
>..
>  'following fills the 8 combo boxes correctly
> ToolSet.MoveFirst
>  Do Until ToolSet.EOF
>    TempToolVar = ToolSet.Fields("ToolName").Value
>    For I = 1 to 8    
>      frmTool.ToolName(I).AddItem TempToolVar
>    Next I
>    ToolSet.MoveNext
>  Loop

>  'offending code - when GToolName(I) is not none....
>  For I = 1 to 8
>    If GToolName(I) <> "[none]" Then  'GToolName is a global variable
>     For J = 0 To frmTool.ToolName(I).ListCount - 1
>        If frmTool.ToolName(I).List(J) = GToolName(I) Then
>'The following line executes then jumps to the ToolName Click event
>          frmTool.ToolName(I).ListIndex = J
>        End if
>     Next J
>    Else
>     frmTool.ToolName(I).ListIndex = frmTool.ToolName(I).ListCount - 1
>    End If
>  Next I

>End Sub



Mon, 04 Jun 2001 03:00:00 GMT  
 Setting Combo box ListIndex initiates Combo box Click event
Lee,

   Thanks!  Tracking makes a lot more sense!

   Do other events fire when the listindex is changed?  There is code
behind the click event that should not run when the listindex is
changed - but I'd like it associated with the combo box.  Is the
change event the best place to move the code?

Maribeth

Quote:

>Sorry, but this action certainly is "by design".  VB fires a click event
>everytime ListIndex is set in code IF setting it changes the ListIndex from
>what it was.  For example, if the .ListIndex is 4, and you execute

>        Combo1.ListIndex = 4

>a click event does not fire.



Tue, 05 Jun 2001 03:00:00 GMT  
 Setting Combo box ListIndex initiates Combo box Click event
I'm only a newbie but I had the same problems. I only wanted the click event
to fire when the user selected an item by mouse rather than when the
listindex was set by code so I did this:

if form.visible then 'makes sure the form is loaded (ie list not getting
loaded at startup)
    if form.activecontrol.name = "listname" then
        'click events here
    end if
end if

what this does is ignores the click event if the user hasn't given it the
focus by selecting it and choosing an item. There are things to watch out
for such as there being no activecontrol or whatever. You may or may not
find this useful but I thought I'd share it.

Dave



Fri, 08 Jun 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Clicking outside combobox trigger click event of the combo box

2. Firing up the Click Event in a Combo when ListIndex is defined

3. enter data in a combo box based on value from another combo box

4. Limit subform combo box by selection in parent combo box

5. Want Access combo box to filter rowsource of another combo box

6. Populating a combo box from another combo box

7. Populate a combo box from another combo box selection

8. selecting records for 2nd combo box dependant on first combo box

9. Help filling second combo box from fist combo box

10. Combo box selection narrows next combo box choices

11. load 2nd combo box - depend on first combo box

12. combo box/database combo box vlaue question - newbie

 

 
Powered by phpBB® Forum Software