Results 1 to 11 of 11

Thread: Listbox items (easy-peasy)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Posts
    81

    Cool

    Now here's an easy yes/no question:
    Can each item of a listbox (or combobox) have its own "Tag"? I'd like to display one thing but underlying it I'd like it to be something compeltely different. An example might be I'd like to show to the user a file name (e.g. "Autoexec.bat") but I'd like to store, associated with that item, the full path (e.g. "C:\Autoexec.bat").

    Is that possible? How?

    Thanks all,
    Toot
    Some cause happiness wherever they go; others, whenever they go.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    You can do somthing like this:
    Code:
    Option Explicit
    
    Private m_MyArray(5) As String ' Size should match the number of entrys in the ListBox
    
    Private Sub Form_Load()
    
        List1.AddItem "Autoexec.bat"
        m_MyArray(0) = "C:\Autoexec.bat"
        List1.AddItem "MyFile.txt"
        m_MyArray(1) = "C:\Program Files\Microsoft Office\Office\Examples\Solver\MyFile.txt"
        
    End Sub
    
    
    Private Sub List1_Click()
    
        MsgBox m_MyArray(List1.ListIndex)
        
    End Sub

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    /// ??? \\\

    yes..also can be done using MS Databound ListBox or ComboBox

    set your listfield to your display item (field1)
    set your boundtext to your hidden item (field2)

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yes, There is a property called ItemData to both listboxes and Combos, you can use it the same way as list
    Code:
        List1.AddItem "Autoexec.bat"
        list1.itemdata(0) = "C:\Autoexec.bat"
        List1.AddItem "MyFile.txt"
        list1.itemdata(1) = "C:\Program Files\Microsoft Office\Office\Examples\Solver\MyFile.txt"
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I guess youre right Martin, i didn't think of that since i never used itemdata
    anyway the listview control has a lot more features including tag's for each item
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Posts
    81

    Cool

    OK folks thanks for your help. Looks like I'll be using the listview control a bit more then

    Toot
    Some cause happiness wherever they go; others, whenever they go.

  8. #8
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Smile Totally off-topic

    Cool name you have

  9. #9
    Lively Member
    Join Date
    Jan 2000
    Posts
    95
    hmmm...Fox...i've notice you've increased a lot in your post count...is it because you helped a lot of people? Or because you've been posting a lot of useless messages like the one above?

  10. #10
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Both I think . I like helping people but also having fun.

    However, I don't care about the post count... it primary tells you how much time people spend on this board

    Oh and most of these posts from me are in the chit chat forum where it doesn't count

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Zej, What are you trying to accomplish? Don't yell on Fox, and definitely not on me or anybody else for posting freely

    The only one caring about postcounts is you!
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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