Image Map of Navigational Panel to Home / Contents / Search Avoiding Bound Controls

SelectItemIndirect - a brief description...

Image of line

This function is specifically designed for use with BindList and BindListEx, in that it allows you to pass the ID of the value you want selected - and then it selects the corresponding list item. If the item passed is not found, then the list is left with nothing selected.

  Sub SelectItemIndirect (lst As Control, ByVal ID As Integer)
    Dim iNum As Integer
    Dim iFound As Integer

    ' Selects an item in a ListBox or Combo based upon
    ' the itemdata value which is passed
    On Error GoTo SelectItemIndirectErr
    If lst.ListCount <> 0 Then
      iFound = False
      iNum = 0
      ' No snazzy way to do this, just loop
      Do
        If lst.itemdata(iNum) = ID Then
          lst.ListIndex = iNum
          iFound = True
        End If
        iNum = iNum + 1
      Loop Until (iNum = lst.ListCount) Or (iFound <> False)
      ' We have run out of items or found something
    End If
  SelectItemIndirectEnd:
    Exit Sub
  SelectItemIndirectErr:
    ' Simple error trap
    MsgBox "Error encountered finding data in List." & BIND_ErrMsg(), 48
    Resume SelectItemIndirectEnd
  End Sub

[RETURN TO MAIN ARTICLE]
Image of arrow to previous article Image of arrow to next article

Image of line

[HOME] [TABLE OF CONTENTS] [SEARCH]