Search code examples
.netvb.netlistbox

.net's ListBox data(large) takes too much time to show up


Im a .net newbie, I ran into a problem where the listbox is taking awfully long time to show up.

This is not the same in java(It took very very less time - one second max).

So, is there any remedy to this??, any other form control??, or some other way??

imports System.Threading
imports System.Windows.Forms

Class form1
         Inherits Form

    Public d As Object() = New Object(400000) {}

    Private lb As ListBox
    Public Sub New()
        lb = New ListBox()
        Controls.Add(lb)
    End Sub

    Public Sub update_list()
        For i As Integer = 0 To 400000
            d(i) = i
        Next
        lb.DataSource = d
    End Sub

    Public Shared Sub main()
        Dim fobj As New form1()
        Dim t As New Thread(AddressOf fobj.ShowDialog)
        t.Start()
        Dim t2 As New Thread(AddressOf fobj.update_list)
            t2.Start()
    End Sub

End Class

Solution

  • You need a control that supports paging, because humans cannot handle this amount of data at one time (regardless of whether the control does).

    Here is one way of using DataGrid that way. See also this question.