Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listbox with 1000+ items freezing Visual Studio

I have a listbox with 1091 items in it, which I am adding during design time. Every time Visual Studio tries to save after I manually populate the listbox it will hang indefinitely. Is there any way around this, am I trying to add too many items to a listbox?

Thanks

like image 540
RHOMBUS Avatar asked Apr 13 '11 16:04

RHOMBUS


2 Answers

Instead of doing it manually city-by-city at design time, I would simply loop through a text filee (or excel file or database) at runtime and add all of the cities to a list, which then is used to populate the listbox.

Of course, this isn't the answer to your current question, but this may be a solution to your current problem.

Update: Resource Files might be a happy medium. You can still keep your city names in some sort of a text file. Then, you add that text file to a resource file. The resource file is then integrated with your program so you don't have to deal with a user ever knowing that the file exists.

I tried it out in C# (my preferred language) and it was more simple than I expected. After adding the resource file Resource1, I added my textfile cityListTextFile.txt to Resource1. From then, I could access it like this:

string cityList = Resource1._cityListTextFile;

After that line of code, I had all of the contents of cityListTextFile.

Take a look at this tutorial on using resource files in VB.NET and a C# one for fun.

like image 127
Yetti Avatar answered Oct 18 '22 13:10

Yetti


Why put so many values on a listbox on design time? Try to add on execution time, so your VisualStudio doesn't hangs.

like image 27
ThoriumBR Avatar answered Oct 18 '22 11:10

ThoriumBR