nickaldri
nickaldri

Reputation: 1

How to handle more than a thousand images in the ListView of winforms?

Hello StackOverFlow Community,

I am trying to load more than a thousand images in my listview but Im getting the OutOfMemoryException. I want to be able to load the images as the user scroll down like a lazy loading experience. how can I achieve that successfully having the following c# code below already?

private void btnAddImg_Click(object sender, EventArgs e)
    {
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.Multiselect = true;
        DialogResult dr = ofd.ShowDialog();
        if(dr == DialogResult.OK)
        {


                foreach (string filename in ofd.FileNames)
                {
                    Image img = Image.FromFile(filename);
                    string a = c.ToString();


                    imageList1.Images.Add(a, img);

                    var listViewItem = listView1.Items.Add("");

                    listViewItem.ImageKey = a;

                    c++;
                }

        }
    }

Upvotes: 0

Views: 79

Answers (0)

Related Questions