Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

listindex and itemdata

Posted on 2001-07-31
5
Medium Priority
?
409 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

705 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