ListView control hangs the application when filling up

A

Amadej

Hello everyone,

I'm doing some tests with SQL CE and decided to use the ListView
control to display data. The problem is the control hangs (freezes)
the whole application if I, for instance, use the slidebar on it to
scroll down a bit.
Just to make sure this only happens with the ListView control, I
created a button and clicked it numerous times, while the list was
filling, and the application continued to respond fine.

The device doesn't seem to be overutilised either, as I can
smart-close the application fine (and start others) even after the
ListView control makes the application stop responding.

Could it be the fact that I have 40.000 records in my SQL database I
am filling into the ListView control?

Here's the code I'm using:

....
ListViewItem lvi;
System.Threading.Thread FillThread;
....
private void button2_Click(object sender, System.EventArgs e)
{
FillThread = new System.Threading.Thread(new
System.Threading.ThreadStart(FillThreadImpl));
FillThread.Start();
}
....
private void FillThreadImpl()
{
try
{
SqlCeCommand oCmd = conn.CreateCommand();
oCmd.CommandText = "SELECT RTRIM(ProductName),RTRIM(ListPrice)
FROM Produkti";
SqlCeDataReader oReader = oCmd.ExecuteReader();

while (oReader.Read())
{
lvi = new ListViewItem(oReader.GetString(0));
lvi.SubItems.Add (oReader.GetString(1));
listView1.Items.Add(lvi);
}
MessageBox.Show("Done");
}
catch (SqlCeException ex)
{
MessageBox.Show("SQL+ " + ex.Message);
}
catch (System.Exception ex)
{
MessageBox.Show("SYS: " + ex.Message);
}
}

Any ideas what could be wrong?

Thanks in advance,
Amadej.
 
C

Chris Tacke, eMVP

You're not seriously putting 40,000 items into the ListView are you? If you
are, then I think you have the answer as to why the app hangs.
 
A

Amadej

Hellow Chris :)

Yes I am. :D Works rather fine as long as I don't touch the listview
control until it finishes loading data. :) A test button with a
MessageBox reacts nice and fast while the data is being populated.

Anyway, it was more for testing purposes than anything else, altho I
will need to find a good way to display 40.000 items in a list
(dataGrid will probably work better.. or will it - there'll still be
the problem of the slidebar reaching it's smallest possible size and
moving for too many records at a time as you slide. I'll probably have
to make an external slidebar and cache data to speed things up... ).

Thank you for your answer and help!
Amadej.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top