473,659 Members | 2,920 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Detail s.BeginUpdate() ;

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

listView_Detail s.BeginUpdate() ;

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

Thanks
PT

Nov 17 '05 #1
3 1225


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
1972
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 control to the page. Then I created a data connection to my table... I right clicked and told it to generate a dataset (which it created dataset1).
14
13320
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 there are a faster way. after all the triggers in the source db already made sure the data was clean. Thanks Alex
0
2612
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 cannot change the size of the ListView's font (ListView.Font) from e.g.
0
2436
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. Currently, I have set the ListView's ContextMenu property a specified instance and it will be activated whenever I right click anywhere within the ListView- regardless of the event happening within a row or within a column header. What's the simplest way...
2
2962
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, etc. The ListView is in Details, with headers and an Icon. What I am trying to accomplish is to rename/append check mark file massively (at once). This is accomplished by the user inputting a name into a provided
6
1561
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 invoke data in other area of my app. Here's some example code: ////////////////////////////////////// private: System::Void lstTeams_SelectedIndexChanged(System::Object * sender, System::EventArgs * e)
3
1569
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 String Dim strConn As String = "server=Gringotts;uid=sa;pwd=password;database=database"
4
2821
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 advance, Bill
0
2003
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 SmallImageList.TransparentColor to the correct color, the background color of the image becomes the BackColor of the ListView control itself, instead of the row (ListViewItem) color, which I want. Even within the column containing the image, the rest of the column is...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8335
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8747
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.