473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help! Populating a listview takes ages!!

All very simple app which loads a log file, parses it and displays the lines
in a listview.
I was playing about with some largeish files 800K and I noticed that the app
would never return control, it would just sit and consume 100% CPU for
aslong as I could be bothered to wait before I pskill's the app.

Anyway I was playing and found that even the code below takes a matter of
minutes to populate the control:

listView_Details.BeginUpdate();

for( int i = 0; i < 10000; i++ )
{
ListViewItem l = listView_Details.Items.Add( "Hello" );
l.SubItems.Add( "Hello" );
l.SubItems.Add( "Hello" );
l.SubItems.Add( "Hello" );
}

listView_Details.BeginUpdate();

Can somone, please anyone tell me how I can speed this operation up.

Thanks
PT

Nov 17 '05 #1
3 1219


Paul Tomlinson wrote:
All very simple app which loads a log file, parses it and displays the lines
in a listview.
ListView's Add is O(n^2).
Can somone, please anyone tell me how I can speed this operation up.


As a workaround you can collect all the items in a ListViewItem[] and
use AddRange.

--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Nov 17 '05 #2
> ListView's Add is O(n^2).

What do you mean "ListView's Add is O(n^2)"???
Nov 17 '05 #3


Paul Tomlinson wrote:
ListView's Add is O(n^2).
What do you mean "ListView's Add is O(n^2)"???


It's a computer science term that (very roughly) means "doing it n times
takes n^2 effort". (n^2 means n*n here, it's just notation).

So if calling Add 1000 times takes roughly 1000t, then calling it 2000
times taks roughly 4000t, and 3000 times takes rougly 9000t, 4000 times
takes 16000t, and your 10000 times would take 100000t.

t is any arbitry timeunit here; ns, ms, ...

--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: cloverme | last post by:
Hi, I need help populating a listbox from a database on a webform. I created a an access database with a table, fields and data. Then I created a WebForm in vb.net and added a DropDownList...
14
by: Alex | last post by:
Hi, I use pg_restore to load a previously dumped database. (10mil records). the load of the data runs quite fast but when starting creating the triggers for foreign keys it takes forever. Isnt...
0
by: Martin Streller | last post by:
Hello, The code below represents a simple ownerdrawn, Listview class in C#. Its purpose is to avoid the flicker of the MS ListView. So I can't fall back to their one. Does anybody know why I...
0
by: MrNobody | last post by:
I would like to have a ListView where the user can right-lick on any row to have options specific to that row, then also be able to right-click on the column header to get a different menu....
2
by: MikeY | last post by:
Hi all, I am coding window forms in C#. My problem is this: I have created a "Check ListView" or a 'ListView' with checkbox's. I have populated the it with my files from my folders, mps, txt,...
6
by: ReMEn | last post by:
I was wondering how I can use a listview effectively in managed c++ ..net. Basically I'm trying to get the index of the selected item in the list view, then get the "tag" attribute of that item to...
3
by: luna | last post by:
theres no errors in my code - but it does nothing at all - its supposed to be populating text boxes!! any ideas ? (im am pretty new to all this) If Not Page.IsPostBack Then Dim search As...
4
by: Bill2k | last post by:
Could someone please give me an example of using the addhandler statement with the listview item click event. Also, if I could get an example of what the eventhandler would look like. Thanks in...
0
by: svx | last post by:
Hello, I am painting individual rows in a ListView control with different colors, depending on state. I am also using a SmallImageList in Detail view. When I set the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.