Results 1 to 6 of 6

Thread: Thousands of Rows in a Listbox- Visual Basic 2010

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2012
    Posts
    158

    Thousands of Rows in a Listbox- Visual Basic 2010

    Hey everyone..I hope there are some VB experts around that may know the best way to handle thousands of rows in a listbox?

    I'm using Visual Basic Express 2010 and am trying to download a zip file, unzip it, and load the text file into a listbox or textbox. I have the file downloaded and unzipped properly but when trying to load this many records the program takes forever.

    I was reading that a JET database may do what I'm looking for but I'm curious if anyone has experience with another method? The idea is that this list will load (about 60-100K) records and then people will be able to filter the list. I need a good way to get this to load quickly and be able to filter quickly..

    Any suggestions would be appreciated!

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Thousands of Rows in a Listbox- Visual Basic 2010

    A ListBox simply cannot handle that much data in a quick manner. It isn't very practical anyway. Do you think anyone will actually want to see every single one ? My advice is to only add filtered items and not the all the items.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    20

    Re: Thousands of Rows in a Listbox- Visual Basic 2010

    Quote Originally Posted by Niya View Post
    A ListBox simply cannot handle that much data in a quick manner. It isn't very practical anyway. Do you think anyone will actually want to see every single one ? My advice is to only add filtered items and not the all the items.
    I would have to agree with you on this, there seems to be no point in displaying all entries if they are going to get filtered as Niya said just display the filtered results.

  4. #4
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Re: Thousands of Rows in a Listbox- Visual Basic 2010

    Hi there, Play with this code,

    PHP Code:
            If File.Exists(Application.StartupPath "\List.txt"Then
                ListBox1
    .Items.Clear()
                
    Dim a As String My.Computer.FileSystem.ReadAllText(Application.StartupPath "\List.txt")
                
    Dim Arry() As String = {vbNewLine}
                
    Dim b As String() = a.Split(vbNewLine)
                
    ListBox1.Items.AddRange(b)
            Else
                
    MsgBox("File List.txt not found"MsgBoxStyle.Information)
            
    End If 

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Thousands of Rows in a Listbox- Visual Basic 2010

    Quote Originally Posted by hackerspk View Post
    Hi there, Play with this code,

    PHP Code:
            If File.Exists(Application.StartupPath "\List.txt"Then
                ListBox1
    .Items.Clear()
                
    Dim a As String My.Computer.FileSystem.ReadAllText(Application.StartupPath "\List.txt")
                
    Dim Arry() As String = {vbNewLine}
                
    Dim b As String() = a.Split(vbNewLine)
                
    ListBox1.Items.AddRange(b)
            Else
                
    MsgBox("File List.txt not found"MsgBoxStyle.Information)
            
    End If 

    Er, yeah. Don't!

    If you're going down this path at all I would read your file into a list rather than the listbox. This has not only the advantage of being manipulated in memory but also exposes the FindAll method which will allow you to significantly speed up searches. Whether a database would be advantageous depends somewhat on the nature of the records. Do you have a sample of the file we could see?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  6. #6
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Re: Thousands of Rows in a Listbox- Visual Basic 2010

    Quote Originally Posted by dunfiddlin View Post
    Er, yeah. Don't!

    If you're going down this path at all I would read your file into a list rather than the listbox. This has not only the advantage of being manipulated in memory but also exposes the FindAll method which will allow you to significantly speed up searches. Whether a database would be advantageous depends somewhat on the nature of the records. Do you have a sample of the file we could see?

    Sample of which file?. if you mean the text file one want to read then simple create a text file with 1 item per line. Yes this method is so quick.

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