0

I have encountered a small problem with ListView in c# winforms. The purpose of my application was to be able to read in dll files in Windows (Post to read in Windows dll files), I made the two biggest Windows libraries (imageres.dll & shell32.dll). That's when I switched to pifmgr.dll (contains 38 icons), it displays the last icon in the dll file until it reaches the number of items that imageres.dll contains. In the post I showed earlier, the code contained a loop so here is the loop that is made of the code:

    for (int j = 0; j < this.imageList1.Images.Count; j++)
    {
        ListViewItem item = new ListViewItem();
        item.ImageIndex = j;
        this.listView1.Items.Add(item);
    }

But as I said above, I'm going from a dll file of 334 icons to 38 icons so I need to add a code that will allow me to delete the excess items. If you want to see the result of going from a 334 icons dll file to a 38 icons one, here is the result: 334 icons dll file to 38 one

Thanks for helping me.

Edit 1: Is there a way that we can fix the big hole above all the pictures because it's really annoying for me and those who will use this application. Is there a way to fix this?

Edit 2: The form is taking 5 seconds to load and it's a lot of time for just loading one form. I really don't know how to load it faster than 5 secs.

Edit 3: The loop and the images initializing are in the form constructor

    public YourFormName()
    {
        InitializeComponent();
        string dllName = "imageres.dll";
        ltView.SmallImageList = imgListImageres;
        ltView.LargeImageList = imgListImageres;
        cbDllName.Texts = @"%systemroot%\system32\imageres.dll";

        this.Icon = IconExtractor.IconExtractor.Extract("imageres.dll", 24, true);
        
        //Configuring the images like the above code...
        ltView.BeginUpdate();

        ltView.Clear();
        for (int i = 0; i < this.imgListImageres.Images.Count; i++)
        {
            ListViewItem item = new ListViewItem();
            item.ImageIndex = i;
            this.ltView.Items.Add(item);
        }
        ltView.EndUpdate();
        LoadTheme();
    }

I have tried everything but without success, the form still loads slowly. You can see on the code above, I put ltView.BeginUpdate(); and after the loop ltView.EndUpdate(); as I had seen in the Microsoft doc. So the form needs to load faster than that because 4-5 seconds to load a single form is still a long time.

Error404
  • 55
  • 8
  • 1
    A `listView1.Clear()` before the loop? – Ralf Mar 09 '22 at 16:41
  • Not even thought about it! Thank you very much, I will try. :) – Error404 Mar 09 '22 at 16:43
  • It works but I forgot to say something: I don't know if we can fix the big hole above all the pictures because it's really annoying for me and those who will use this application. Is there a way to fix this? – Error404 Mar 09 '22 at 16:47
  • You presumably mean the space before the first distinguishable icon? Have you checked that the first visualized icon is really the first icon taken from the source? Or is that space you see filled with white or transparent(if possible) icons? – Ralf Mar 09 '22 at 17:16
  • I checked if they were empty images but no... You also have to do `listView1.Clear();` before the loop. Also, I have a small problem, when I launch the form, it takes 5 seconds to open and I don't know how to make it load faster because 5 seconds is a lot of time to load only one form. – Error404 Mar 09 '22 at 17:35
  • If it takes a long time to load a listview, use `BeginUpdate` and `EndUpdate`. – Dwedit Mar 09 '22 at 18:37
  • Okay, fine! I hope it works! – Error404 Mar 09 '22 at 19:24
  • I forgot to say but for the initialization of the form with the listView1, it is directly in the constructor of the form. So it takes the same time. I've searched but I still haven't found anything functional on Google. I tried to use the "this.SuspendLayout();"/"this.ResumeLayout();" but obviously it doesn't help the form to load. So it doesn't work, it takes the same time to start.I'm back to my 5 seconds, sorry but 5 seconds, for a simple form, with only one custom control, it's strange. – Error404 Mar 10 '22 at 18:36

0 Answers0