CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 32
  1. #1
    Join Date
    Oct 2007
    Posts
    72

    List Box max item

    Hi guys,

    I found that the max item for list box in VB is around 32k items (index will be negative if more than that amount). Is there any ways to add more than 32k items in List Box ? maybe use similar control ? Thank you before

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: List Box max item

    When you have more than 32K items in a list box, that means the way you are approaching the solution is wrong. Do you expect a User to go through 32K items to select what he/she wants. May be you need to re-look at how you are doing things.

  3. #3
    Join Date
    Oct 2007
    Posts
    72

    Re: List Box max item

    The problem is, i cannot change how the application works since it is not designed by me. This list box is for listing down all the product that we have. Actually, there are some workaround for this :
    1. categorized the product, and then add 1 combo box for the category. the product populated will only be the product that user choose.
    2. Use 1 temporary variable to contain all the Product Code and Display only 32k first item, and add "Continue..." as the last item to go to the rest of the item.

    However, i just feel that there must be a way to populate all the ProductCode without using this workaround.

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: List Box max item

    The maximum that a list box can hold is 32K. I guess you will have to go with the work around.

  5. #5
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: List Box max item

    Yes, the limit is exactly 32767, which is max. positive integer value.

    You might replace the ListBox with an apropriately configured ListView. I think, a Listview's index is a Long, so you wouldn't come to a limit so fast.
    You have to add 'Microsoft Windows Common Controls 6.0' to your toolbox and get a ListView control on your form.
    Note that the ListView has different structure and therefore different syntax to the ListBox, but it's more versatile.

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: List Box max item

    Read it into a string array, and then load 100 AT A TIME, ONLY. Have the user select a letter before you show ANY of them.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: List Box max item

    With Davids method i'd use a combobox to do the selection...

    Done it before and it works like a charm...

    It does require a little more coding but belive me, it'll add that little something extra to the app that makes it soooo much more pro...

    good advice here david..

    Gremmy..
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  8. #8
    Join Date
    Apr 2008
    Location
    Philippines, Manila
    Posts
    19

    Re: List Box max item

    use database instead of listbox...^_^

  9. #9
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: List Box max item

    Quote Originally Posted by psychi_beavis
    use database instead of listbox...^_^
    It's coming out of a db
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  10. #10
    Join Date
    Sep 2011
    Location
    Preveza Greece
    Posts
    9

    Re: List Box max item

    Scroll Bar in VB have limit of 32767 items. But this isn't a problem for making a list box as a user control to manage say 500000 items using a VScrollBar.
    I wrote a user control named Fat List Box, and in the attachment below is an example of using it.
    this is a part of coding on a Vscroll inside user control:
    LINES are lines we see on listbox
    Logicallines times Vscroll1.max are items on the list (but maybe some more less than logicallines, so for last page we do trick..as you read:
    topitem is the hidden item before the item at first visible line


    Private Sub VScroll1_Change()
    If Not State Then
    If logicallines > LINES Then
    If VScroll1 = VScroll1.Max Then
    topitem = itemcount - LINES - 1
    Else
    topitem = (VScroll1 * logicallines) \ 2
    End If
    Else
    topitem = (VScroll1 * LINES) \ 2
    End If
    IsCur = False
    Timer1.Enabled = True
    End If
    End Sub
    Attached Files Attached Files

  11. #11
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: List Box max item

    3 year old question that was already answered.
    Always use [code][/code] tags when posting code.

  12. #12
    Join Date
    Sep 2011
    Location
    Preveza Greece
    Posts
    9

    Re: List Box max item

    So it is wrong for you the adding of a user control by me? (sorry my english is terrible, i wrote as i speak Greek)

  13. #13
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: List Box max item

    The question is 3 years old and was answered, no point in rasing a post from the dead not to mention a list box that holds more than 32 k items is pretty well useless as no one in thier right mind would put a list box on a form with that many items in it.
    Always use [code][/code] tags when posting code.

  14. #14
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: List Box max item

    Not to mention that it's SLOW, and pretty hard to get a good INDEX reference in the 140th page of data...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  15. #15
    Join Date
    Sep 2011
    Location
    Preveza Greece
    Posts
    9

    Re: List Box max item

    In our days computers are very fast. Even the population of my listbox with 500000 items is very fast. I have an application named fotodigitallab which introduce the FotoList a big list of images as names in this listbox (earlier version, with one colour for all items), which maps a tree of folders from a mass media (hard disk or memory card). If anyone have an 8 gigabyte memory card it is possible to have >32k jpgs files. From scroll bar you can go to any "page" (as dglienna says). It is a search with one control. So before three years...8 gigabytes card was rare, but know we can face problems who needs a control with more than 32k items.
    I think a listbox first for the user interaction, no to substitute an array or even better an advanced data object. It is possible to make a guicksort on the items, from an offset A to an offset B (in the example I haven't include the sort routine). In my mind the listbox has a temporary use. You have all you need in the memory, so you don't save data for later use as with a database.

Page 1 of 3 123 LastLast

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