Link to home
Start Free TrialLog in
Avatar of tlw2651
tlw2651

asked on

listindex and itemdata

I am loading a combobox using the following code

Do Until rsData.EOF
                             
cboFloor.AddItem rsData("DESC_Floor").Value & ""
cboFloor.ItemData(cboFloor.NewIndex) = rsData("PKID_Floor").Value & ""
rsData.MoveNext
                             
Loop

In this case it loads the floors of a building and the combobox would contain the following data:

ListIndex   List                 ItemData
0           First Floor          111
1           Second Floor         112
2           Third Floor          113

The combobox data loads without a problem.  However, in some cases I have a floor preselected.  In these cases I want the combobox to load completely and to have that floor selected by the program.  This is easily done with "cboFloor.ListIndex = mi_ListIndex" but the data I have is the ItemData.   How can I convert the ItemData number (which I have) to the corresponding ListIndex number (which I need to make this work).

Thanks
Avatar of casassus
casassus

for i= 1 to cboFloor.ListIndex
  if cboFloor.itemdata(i) = NumBerIWantToFind then
    ' Make what you want
    Exit for
  end if
next
Private Sub Combo1_Change()
  Combo1_Click
End Sub

Private Sub Combo1_Click()
  MsgBox Combo1.ItemData(Combo1.ListIndex)
End Sub
To be more efficient, combine your loading loop with the selection loop proposed by casassus.

Zaphod.
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tlw2651

ASKER

Had to change the flow a little, but that was it.  Excellent solution.