C # listview imagelist quickly adds a lot of elements

I have a ListView and ImageList in C # in my form and read a directory with a maximum number of files per 1000 files. I pre-populate the ListView and ImageList with the number of FileItems DummyItems using the AddRange methods to avoid flickering and scaling of the ListView.

Now in the second stage, I just wanted to assign information about the correct object to the fictitious elements, while I was reading real objects from the file system. The sofar position text is not a problem, but I cannot replace the dummy images. If I try to do this, it throws an invalid argument exception. To remove an image using RemoveAtIndex or RemoveAtKey and then re-adding it will take me a while to iterate through 1000 files. 1000 files take 8 minutes with "RemoveAtKey" in ImageList. "RemoveAtKey" is the bottleneck that I recognized. If I try to clear all images before and again using AddRange, my element images will be empty or an exception will occur. Does anyone know how I get 1000 different thumbnails from 1000 files with a file name quickly in a listview control using other methods than I use?

+4
source share
1 answer

First of all, you can create a new control named "ListViewNF" with the following code:

class ListViewNF : System.Windows.Forms.ListView { public ListViewNF() { //Activate double buffering this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); //Enable the OnNotifyMessage event so we get a chance to filter out // Windows messages before they get to the form WndProc this.SetStyle(ControlStyles.EnableNotifyMessage, true); } protected override void OnNotifyMessage(Message m) { //Filter out the WM_ERASEBKGND message if(m.Msg != 0x14) { base.OnNotifyMessage(m); } } } 

This eliminates flickering problems when adding items to the list view at high speeds.

I am still doing some research and tests for your other problem.

0
source

All Articles