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;
}
}