Results 1 to 15 of 15

Thread: Need Light Weight List Control With .TAG for Each Line

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Location
    Anywhere I want to.
    Posts
    167

    Need Light Weight List Control With .TAG for Each Line

    Can use a ListView Report but do not want to ! Too much coding and maintenance.

    Looking for a VB6 control like a ListBox that has a .Tag property for each list row.
    Header not required.
    Need both scrollbars available.

    Anything available ?

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Location
    Anywhere I want to.
    Posts
    167

    Re: Need Light Weight List Control With .TAG for Each Line

    Sorry "LightWeight" was not what I meant, as in Shape or Line etc.

    To clarify in this instance I mean a control that does have the minimal features.
    Like a ListBox.

    .ListCount
    .Selected )AKA Checkboex)
    .List(Index)
    .ItemData(Index) OPTIONAL
    .Remove(Index)

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,684

    Re: Need Light Weight List Control With .TAG for Each Line

    Are the Values you want to store in that "per Item"-TAG-Property unique?
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,133

    Re: Need Light Weight List Control With .TAG for Each Line

    Quote Originally Posted by LorinM View Post
    Sorry "LightWeight" was not what I meant, as in Shape or Line etc.

    To clarify in this instance I mean a control that does have the minimal features.
    Like a ListBox.

    .ListCount
    .Selected )AKA Checkboex)
    .List(Index)
    .ItemData(Index) OPTIONAL
    .Remove(Index)
    There is no Tag property for each ListItem, so you have to maintain an additional array/collection to store these.

  5. #5
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    782

    Re: Need Light Weight List Control With .TAG for Each Line

    If you're not overly worried about reusing this, just use the ItemData property on the ListBox control to hold an index into another [hidden] ListBox that holds your "Tags".

    Code:
    List1.AddItem( "Fred" )
    List2.AddItem( "Flintstone" )
    List1.ItemData( List1.NewIndex ) = List2.NewIndex 
    
    Dim sTag as String : sTag = List2.List( List1.ItemData( List1.ListIndex ) )
    '                           \________/  \____________/  \_____________/
    '                            |           |               |
    '                            |           |               Selected Item in List1
    '                            |           Index into 'Tags' list
    '                            Extract tag
    If you are likely to reuse this, wrap these two into a UserControl.

    Regards, Phill W.

  6. #6
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,439

    Re: Need Light Weight List Control With .TAG for Each Line

    Yeah, my first thought was bite the bullet and use the ListView.

    However, using a VB6 collection (which doesn't require another reference) that mirrors your ListBox would also be a trivial solution. You'd just have to figure out what to use for the key for your collection. Maybe I'll work out some simple procedures to do this and post them. Sounds like a fun little project.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  7. #7
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,439

    Re: Need Light Weight List Control With .TAG for Each Line

    Hmmm, it turns out that there's just nothing that I can see to uniquely identify the items in a ListBox, not even with API calls. So, to handle duplicates, it'd take some sophisticated tracking of the index values (which are subject to change).

    I suppose another option is to set a tab in the ListBox that's off the right side, and then put some hidden text out there to be used as your Tag.

    However, rather than do all of that, the ListView is just trivially does it, so that's truly the way to go.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Location
    Anywhere I want to.
    Posts
    167

    Re: Need Light Weight List Control With .TAG for Each Line

    Has not someone connected a ListBox and Collection to make a, what I would call, a proper listbox.
    MS should of made ItemData a variant, Oh well.

  9. #9
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    714

    Re: Need Light Weight List Control With .TAG for Each Line

    You may look at makeing your own custom listbox I did one years back by rendering the items onto a picturebox and scrollbars were need. I found this maybe not what your looking for but may give you can idea

    https://www.vbforums.com/showthread....n-32-767-Items

    also this may give you some ideas good luck
    https://www.vbforums.com/showthread....andard-ListBox

  10. #10
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,133

    Re: Need Light Weight List Control With .TAG for Each Line

    Quote Originally Posted by LorinM View Post
    Has not someone connected a ListBox and Collection to make a, what I would call, a proper listbox.
    MS should of made ItemData a variant, Oh well.
    Use the itemdata as index to an array of an UDT, then you can store anything you need in it

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Location
    Anywhere I want to.
    Posts
    167

    Re: Need Light Weight List Control With .TAG for Each Line

    Using a UDT get messy when Removing a list item.

  12. #12
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,118

    Re: Need Light Weight List Control With .TAG for Each Line

    you can wrap a list view in a user control and minimize the work required to manage it

    building your own list control with just what you want will probably be more work. i've have basically completely given up on list boxes at this point. i always want a list view with filtering capabilities and simplified api now. the extra wrappers like copy column or copy all or simplified adding sub elements is nice to have by default

    https://www.vbforums.com/showthread....rol&highlight=
    Last edited by dz32; Aug 15th, 2024 at 06:34 PM.

  13. #13
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,133

    Re: Need Light Weight List Control With .TAG for Each Line

    Quote Originally Posted by LorinM View Post
    Using a UDT get messy when Removing a list item.
    What is the purpose of the listbox?
    Most often it's used for displaying a static list to users

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Location
    Anywhere I want to.
    Posts
    167

    Re: Need Light Weight List Control With .TAG for Each Line

    Yes, but I need an ItemData that will hold at least String?
    I have written one now, MyListBoxEnhanced, that I am converting to a usercontrol.
    Wish me luck since my skills are diminishing with age.

  15. #15
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    714

    Re: Need Light Weight List Control With .TAG for Each Line

    Good look with your listbox. you can also look at one I made to for idea a bit old now and may need updating a bit.
    https://github.com/Planet-Source-Cod...stbox__1-65554

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