
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