Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

listindex and itemdata

Posted on 2001-07-31
5
Medium Priority
?
410 Views
Last Modified: 2008-03-06
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
0
Comment
Question by:tlw2651
5 Comments
 
LVL 3

Expert Comment

by:casassus
ID: 6338050
for i= 1 to cboFloor.ListIndex
  if cboFloor.itemdata(i) = NumBerIWantToFind then
    ' Make what you want
    Exit for
  end if
next
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6338060
Private Sub Combo1_Change()
  Combo1_Click
End Sub

Private Sub Combo1_Click()
  MsgBox Combo1.ItemData(Combo1.ListIndex)
End Sub
0
 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 6338214
To be more efficient, combine your loading loop with the selection loop proposed by casassus.

Zaphod.
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 200 total points
ID: 6339988
Dim intFloorToSelect As Integer

Do Until rsData.EOF
                           
  cboFloor.AddItem rsData("DESC_Floor").Value & ""
  cboFloor.ItemData(cboFloor.NewIndex) = rsData("PKID_Floor").Value & ""
  If cboFloor.ItemData(cboFloor.NewIndex) = FloorToPreselect Then ' Test for matching floor
    intFloorToSelect = cboFloor.NewIndex
  End If
  rsData.MoveNext
                           
Loop

cboFloor.ListIndex = intFloorToSelect

If the desired floor is found in the itemdata property for each newly added row then this will be preselected when the combo is fully populated. If the matching floor is not found at all then the selected item will be index 0.
0
 

Author Comment

by:tlw2651
ID: 6341309
Had to change the flow a little, but that was it.  Excellent solution.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question