Home All Groups Group Topic Archive Search About

Vb.net[2008] Combo box population from text file (40,000 lines!)

Author
15 May 2009 8:22 PM
Rob W
Greetings,

The vb.net application I'm developing is for data input and have utilised a
combo box which is populated with a list of UK towns.

As it is 40,000 lines long I have recently had problems testing the
application as it doesn't always run when using the standard F5 - Start
debugging a problem which doesn't occur when I removed the code to populate
the combox box.

It is a lot of records to scroll through, but wtih the suggestive text input
only 2-3 characters are usally needed until your town is a click away.

Thinking maybe its to ambitious to populate with 40,000 items.



Code below populates the combo box:-

'StreamReader to read towns from a text file

Dim townfile As New System.IO.StreamReader(Application.StartupPath +
"\towns.txt", System.Text.Encoding.Default)



' Read file until no more data exists . i.e. BLANK LINE found

Do While townfile.Peek <> -1

    Dim LineIn As String = townfile.ReadLine()

    cboTown.Items.Add(LineIn)

Loop



I did look at other solutions like loading the data into an Array,
Stringbuilder, list and looking at I could use a buffer somehow.

I did try to use an 1d string array and use the streamReader ReadtoEnd
mnethod but I couldn't get the conversion types right :-(

Any ideas how I make the process more efficient to populate a combo box with
40,000 + items?



Cheers

Rob

Author
15 May 2009 9:13 PM
Armin Zingler
Rob W wrote:
> Any ideas how I make the process more efficient to populate a combo
> box with 40,000 + items?

How fast do you expect it? The following code takes 1.7 seconds:
(40,000 lines, each 30 characters, Athlon64 X2 4400+ 2.2GHz)

Me.ComboBox1.Items.AddRange( _
    IO.File.ReadAllLines("e:\test.txt", System.Text.Encoding.Default) _
)


Armin
Author
15 May 2009 11:06 PM
Rob W
I will give that a go, I did look at using Add Range but for some reason
didn't think I could user the file contents (stupid I know since I was using
the same concept just one line at a time populating the combo box in a
loop).

I was attempting to put the contents of a file in an array and then add into
the combo box via AddRange, daft I know!

Thanks

Show quoteHide quote
"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:eBh5SJa1JHA.4272@TK2MSFTNGP06.phx.gbl...
> Rob W wrote:
>> Any ideas how I make the process more efficient to populate a combo
>> box with 40,000 + items?
>
> How fast do you expect it? The following code takes 1.7 seconds: (40,000
> lines, each 30 characters, Athlon64 X2 4400+ 2.2GHz)
>
> Me.ComboBox1.Items.AddRange( _
>    IO.File.ReadAllLines("e:\test.txt", System.Text.Encoding.Default) _
> )
>
>
> Armin
Author
15 May 2009 10:26 PM
Mike
See if using VIRTUAL LIST controls features is possible, where you
tell the list control the bounds and it will issue an callback with a
index to the view port for the amount you want to show per page.

I'm new to .NET but Virtual list controls  have been been part of the
Windows GUI tools library since MFC specifically design to handle
large list data needs.

I'm sure the VB.NET class have incorporated the same needs. If
directly, you can always do owner drawn controls.

Search for:

     virtual list controls for .NET

--



Rob W wrote:
Show quoteHide quote
> Greetings,
>
> The vb.net application I'm developing is for data input and have utilised a
> combo box which is populated with a list of UK towns.
>
> As it is 40,000 lines long I have recently had problems testing the
> application as it doesn't always run when using the standard F5 - Start
> debugging a problem which doesn't occur when I removed the code to populate
> the combox box.
>
> It is a lot of records to scroll through, but wtih the suggestive text input
> only 2-3 characters are usally needed until your town is a click away.
>
> Thinking maybe its to ambitious to populate with 40,000 items.
>
>
>
> Code below populates the combo box:-
>
> 'StreamReader to read towns from a text file
>
> Dim townfile As New System.IO.StreamReader(Application.StartupPath +
> "\towns.txt", System.Text.Encoding.Default)
>
>
>
> ' Read file until no more data exists . i.e. BLANK LINE found
>
> Do While townfile.Peek <> -1
>
>     Dim LineIn As String = townfile.ReadLine()
>
>     cboTown.Items.Add(LineIn)
>
> Loop
>
>
>
> I did look at other solutions like loading the data into an Array,
> Stringbuilder, list and looking at I could use a buffer somehow.
>
> I did try to use an 1d string array and use the streamReader ReadtoEnd
> mnethod but I couldn't get the conversion types right :-(
>
> Any ideas how I make the process more efficient to populate a combo box with
> 40,000 + items?
>
>
>
> Cheers
>
> Rob
>
>
Author
15 May 2009 11:07 PM
Rob W
I will look into this, thanks for the input.

Show quoteHide quote
"Mike" <unkn***@unknown.tv> wrote in message
news:ezzXtwa1JHA.5684@TK2MSFTNGP04.phx.gbl...
> See if using VIRTUAL LIST controls features is possible, where you tell
> the list control the bounds and it will issue an callback with a index to
> the view port for the amount you want to show per page.
>
> I'm new to .NET but Virtual list controls  have been been part of the
> Windows GUI tools library since MFC specifically design to handle large
> list data needs.
>
> I'm sure the VB.NET class have incorporated the same needs. If directly,
> you can always do owner drawn controls.
>
> Search for:
>
>     virtual list controls for .NET
>
> --
>
>
>
> Rob W wrote:
>> Greetings,
>>
>> The vb.net application I'm developing is for data input and have utilised
>> a combo box which is populated with a list of UK towns.
>>
>> As it is 40,000 lines long I have recently had problems testing the
>> application as it doesn't always run when using the standard F5 - Start
>> debugging a problem which doesn't occur when I removed the code to
>> populate the combox box.
>>
>> It is a lot of records to scroll through, but wtih the suggestive text
>> input only 2-3 characters are usally needed until your town is a click
>> away.
>>
>> Thinking maybe its to ambitious to populate with 40,000 items.
>>
>>
>>
>> Code below populates the combo box:-
>>
>> 'StreamReader to read towns from a text file
>>
>> Dim townfile As New System.IO.StreamReader(Application.StartupPath +
>> "\towns.txt", System.Text.Encoding.Default)
>>
>>
>>
>> ' Read file until no more data exists . i.e. BLANK LINE found
>>
>> Do While townfile.Peek <> -1
>>
>>     Dim LineIn As String = townfile.ReadLine()
>>
>>     cboTown.Items.Add(LineIn)
>>
>> Loop
>>
>>
>>
>> I did look at other solutions like loading the data into an Array,
>> Stringbuilder, list and looking at I could use a buffer somehow.
>>
>> I did try to use an 1d string array and use the streamReader ReadtoEnd
>> mnethod but I couldn't get the conversion types right :-(
>>
>> Any ideas how I make the process more efficient to populate a combo box
>> with 40,000 + items?
>>
>>
>>
>> Cheers
>>
>> Rob
>>