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 45,000 lines long there are 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.

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 efficent to populate a combo box with 45,000 + items?

PS I'm a vb.net newbie

Cheers
Rob

Do you think there are users of your application out there who want to search through a 45000+ lines combobox to find the city they want?

Typing the first 1,2 or 3 character(s) will more than likely narrow it down to the town they need and will be one click away from completing the field.

Imo it is a practical solution to find the town, a technical one of loading in 45,000 Items I ain't too sure.

I agree with the other posts that 45k items is a bit much and you may be better off creating a series of dependant combo boxes instead.

One thing that may help however is that when you're populating such a huge amount of items, you should use the following syntax to regain a bit of speed.

cboTown.SuspendLayout()
Do While townfile.Peek <> -1
Dim LineIn As String = townfile.ReadLine()
cboTown.Items.Add(LineIn)
Loop
cboTown.ResumeLayout()

Just to echo what has been said before:

45000 lines in a combo box = pure daftness

You need to think of a redesign!!!

This article has been dead for over six months. Start a new discussion instead.