CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2000
    Location
    Brooklyn, NY
    Posts
    18

    Need a new ListBox

    I need to add one particular quality to the ListBox to fit my needs. Each item added needs to have not just text but a variable along with it. This variable will be there to signify a catagory of the item. The catagory can't be shown, but is there so that if a user selects the item, the code will know what catagory to work with. The list of catagories will be a predetermined ammount, so I guess that the variable can refer to an Enumeration. I would like the line of code I write for the AddIem to look like this:

    list1.AddItem ("This is the text.", Catagory1)



    I assume that I need to use the ListBox in making a new ocx. How do I add this new bit of depth to the ListBox? Thanks for any help that anyone can give me.


  2. #2
    Join Date
    Jun 2001
    Location
    Israel
    Posts
    228

    Re: Need a new ListBox

    you can use 2 listboxes. 1 for data & one for variable. if you don't need it sorted, add them together (to different listboxes) and they will have the same index, if not... think of something, i'm sure there is a way to overcome this too.

    ----------
    The @host is everywhere!
    ----------

  3. #3
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Need a new ListBox

    Each Listbox item has a corresponding ITEMDATA method associated with it. It is a numerical value and can be used as a pointer to array element or a enumeration element etc.
    Here is a very simple example:

    option Explicit
    Dim strMyarray(20)
    private Sub Form_Load()
    Dim X
    strMyarray(0) = "This is Item 0"
    strMyarray(1) = "This is Item 1"
    strMyarray(2) = "This is Item 2"
    strMyarray(3) = "This is Item 3"
    strMyarray(4) = "This is Item 4"
    strMyarray(5) = "This is Item 5"
    strMyarray(6) = "This is Item 6"
    strMyarray(7) = "This is Item 7"
    strMyarray(8) = "This is Item 8"
    strMyarray(9) = "This is Item 9"
    strMyarray(10) = "This is Item 10"
    for X = 1 to 10
    List1.AddItem "Something in a list Number " & X
    List1.ItemData(List1.NewIndex) = X
    next X
    End Sub

    private Sub List1_Click()
    Debug.print strMyarray(List1.ItemData(List1.ListIndex))
    End Sub




    John G

  4. #4
    Join Date
    Dec 2000
    Posts
    66

    Re: Need a new ListBox

    You can use a listbox and a collection object.

    As shown below:

    Dim colList as New Collection

    private sub adding()

    List1.AddItem "item1"
    colList.Add Category1, "key" & List1.NewIndex

    end sub


    //-----------------------------------------\\
    Where there's a wire , there's a way
    \\-----------------------------------------//

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

Featured