mardi 3 mars 2015

How can i load items back to the listView control from text file and also add checkBoxes near each item faster?

In this method i'm reading a text file from my hard disk and add the items to the listView.


I also changed in the form1 designer on the listView propeties the property CheckBoxes to true.


Now when i'm running my program it's taking like 10-15 seconds to load it up all.


The form1 constructor:



LoadtoListView();


And the method LoadtoListView:



private void LoadtoListView()
{
int countit = 0;
using (StreamReader sr = new StreamReader(@"c:\listviewfile\databaseEN.txt"))
{
while (-1 < sr.Peek())
{
try
{
string name = sr.ReadLine();
string email = sr.ReadLine();
var lvi = new ListViewItem(name.Substring(name.IndexOf(":") + 1));
lvi.SubItems.Add(email.Substring(email.IndexOf(":") + 1));
listView1.Items.Add(lvi);
countit++;
}
catch (Exception) { }
}
sr.Close();
numberofforums = countit;
}
}


There are 547 items to load and 547 checkBoxes.


I tested now if i change in the designer the listView property of the CheckBoxes to false again it will load fast about 1-2 seconds.


But once i'm turning this property of the CheckBoxes to true it's tkaing more then 10-15 seconds to load.


I guess the problem is that it's taking time to draw all the CheckBoxes.


Is there any way to make it all faster ?


Aucun commentaire:

Enregistrer un commentaire