Results 1 to 3 of 3

Thread: Adding Another Column to a ComboBox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2000
    Location
    Edmonton,AB, Canada
    Posts
    30

    Question

    Greetings,

    I have a combo box on a form which I am automatically
    filling in with items that have an assoicated page number.
    For Example:
    Utilities is Page 2
    Approach is Page 3
    Abutments is Page 4

    In the combo box the list items are sorted in alphabetical order:
    Abutments is page 4
    Approach is page 3
    Utilities is page 2

    I need to add another column to the combo box to store the
    page number, can anyone tell me how to add this second
    column and then fill it with the proper page number?

    In addition the second column needs to be hidden from the
    user but accessible to code. I have tried using the combo box found in Micrsoft Form 2.0 Object Library but it just doesn't fit cut it.

    I can not use a array or a recordset to do this because
    the search cabilities are just to slow for the amount
    of data I am dealing with.

    Thank you in advance for your help.
    David L. Baudais
    Systems Analyst


  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    You could use the ItemData property for this.
    eg
    To load:
    Combo1.AddItem "Utilities"
    Combo1.ItemData(Combo1.NewIndex) = 2
    Combo1.AddItem "Approach"
    Combo1.ItemData(Combo1.NewIndex) = 3
    Combo1.AddItem "Abutments"
    Combo1.ItemData(Combo1.NewIndex) = 4

    To retrieve the page number of the selected item:

    msgbox "Page " & Combo1.ItemData(Combo1.ListIndex)



  3. #3
    Guest
    The only way I see is using the ImageCombo control which is in the Microsoft Windows Common Controls.
    Code:
    'Syntax:
    'ImageCombo1.ComboItems.Add [Index], [Key], [Text], [Image], [SelImage], [Indentation]
    
    ImageCombo1.ComboItems.Add , "Page 2", "Utilities is page 2"
    ImageCombo1.ComboItems.Add , "Page 3", "Approach is page 3"
    ImageCombo1.ComboItems.Add , "Page 4", "Abutments is page 4"
    You can't use keys like "1" for keys because VB requires alphabet characters in each key.
    That way you can get the page number like this:

    Code:
    PageNum& = Right(ImageCombo1.SelectedItem.Key, 1)
    Hope this helps.

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