Results 1 to 4 of 4

Thread: Combo1.ItemData problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Wink Combo1.ItemData problem

    I have a text file with FirstNames and LastNames:

    "names.txt"
    Tom, Johns
    Joe, Jordan
    Ted, Brown
    ...etc.

    There's a ComboBox & a Label on the form.

    I want to read in FirstNames (first column) into a ComboBox, and somehow reference to them LastNames (second column). So when user selects a first name from ComboBox, the corresponding Last name will show on a Label beside it.

    example (see names above):
    user clicks on Joe in the ComboBox, and Jordan appears in on the Label.

    ---------------------------------------------------------
    MSDN suggests using .ItemData property but I couldn't get it to work with my file access stuff.
    MSDN's example of .ItemData

    Private Sub Form_Load ()
    ' Fill List1 and ItemData array with
    ' corresponding items in sorted order.
    List1.AddItem "Judy Phelps"
    List1.ItemData(List1.NewIndex) = 42310
    List1.AddItem "Chien Lieu"
    List1.ItemData(List1.NewIndex) = 52855
    List1.AddItem "Mauro Sorrento"
    List1.ItemData(List1.NewIndex) = 64932
    List1.AddItem "Cynthia Bennet"
    List1.ItemData(List1.NewIndex) = 39227
    End Sub

    Private Sub List1_Click ()
    ' Append the employee number and the employee name.
    Msg = List1.ItemData(List1.ListIndex) & " "
    Msg = Msg & List1.List(List1.ListIndex)
    Label1.Caption = Msg
    End Sub

    ---------------------------------------------------------
    Any suggestions?

    Thanx again

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    here is a quick fix.

    have a hidden listbox which contains only the last names. when a user clicks on one of the first names in the combo box, reference the hidden listbox with the same index from the combo box, and you have your last name, which you can place into the label.

    Is this what you needed to do?
    -Shickadance

  3. #3
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Shickadance is right. Only numeric (Long) values can be stored in the ItemData property array of a combo or listbox.
    "It's cold gin time again ..."

    Check out my website here.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Red face

    Thanks guys, but I don't think this is going to work because I need to add the names to the text file as I go along. Also I wouldn't be able to sort the combobox without losing ties between FirstNames & LastNames.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width