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
Do Until rsData.EOF
cboFloor.AddItem rsData("DESC_Floor").Value
cboFloor.ItemData(cboFloor
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
Private Sub Combo1_Change()
Combo1_Click
End Sub
Private Sub Combo1_Click()
MsgBox Combo1.ItemData(Combo1.Lis tIndex)
End Sub
Combo1_Click
End Sub
Private Sub Combo1_Click()
MsgBox Combo1.ItemData(Combo1.Lis
End Sub
To be more efficient, combine your loading loop with the selection loop proposed by casassus.
Zaphod.
Zaphod.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Had to change the flow a little, but that was it. Excellent solution.
if cboFloor.itemdata(i) = NumBerIWantToFind then
' Make what you want
Exit for
end if
next