tags:

views:

71

answers:

4

I have a listview, which is used as an index to a simple search application. Each item of the index is a word, and clicking on the item will add that item to the search textbox. The user can first click on any of the words she/he prefers to and them to the search textbox and then click search, to search in the documents. The problem is that adding more than around 1000 items to a ListView takes a lot of runtime! I have designed a progressbar and added a timer which starts adding items to the listview as soon as the form loads. This gives responsiveness to the application, but still the efficiency is very low. I suspect there might be around 100,000 words in the index when the document base grows enough so I need a more efficient way to do this. Maybe I need to change the ListView component to something else. This is the code in the timer to add the items to the listview:

if (!listViewDone)
        {
            int pos = 0;
            ListView listView1 = Search.getInstance().getListView();
            listView1.BeginUpdate();
            for (pos = listViewPos; pos < termf.Count && pos < listViewPos + listViewChunk; ++pos)
            {
                TermFreq t = termf[pos];
                listView1.Items.Add(new ListViewItem(new String[] { t.term }));
                progressBar1.Value = pos;
            }
            listView1.EndUpdate();
            listViewPos = pos;

            if (pos == termf.Count)
            {
                listViewDone = true;
                termf = null;
                timer1.Enabled = false;
                Visible = false;
            }
        }
+2  A: 

Don't use a list-view, it wasn't meant to handle so many items and even with perfect performance will annoy your users. Consider using an auto-complete textbox instead.

Jonathan Allen
The costumer has demanded such a view. He has a similar application with a listed index. The difference is that a costumer can see what is in the index without typing anything, but just scrolling around.
Mostafa Mahdieh
while ultimately you have to do what they say, I would still suggest putting the other option in front of them. Perhaps with a Show All button that pop-ups a full screen list. (In fact, I may just do that for my project.)
Jonathan Allen
A: 

I checked the listbox instead of listview and its way faster! The whole process takes less than a second, which was at least 30X.

Mostafa Mahdieh
+2  A: 

If you need to display that many items in a ListView, your best option is using the ListView's Virtual Mode. This way your ListView will only display visible items.

hmemcpy
+3  A: 

As hmemcpy mentioned, the VirtualMode will speed things up considerably. I'm not sure about the commercial nature of the project but I have used the excellent open source ObjectListView which includes a FastObjectListView variant.

This is basically an extended virtual ListView that is extremely fast and as an added bonus is much nicer to work with. The documentation claims it "can build a list of 10,000 objects in less than 0.1 seconds" and while I can't vouch for that whenever I have used it I've never noticed any serious lag. The licensing could be an issue for you though.

Lummo