4 Replies - 324 Views - Last Post: 14 November 2012 - 08:23 PM Rate Topic: -----

#1 C#Guy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 21-February 12

When new image is added previous images changed in listview.

Posted 14 November 2012 - 01:40 AM

Hi everybody,
I'm quite new to listviews. I'm trying to display images in the listview. When I add new item all the previous items change into the new one. So the listview is having same images. I'm done googling and still I can't find the solution. Please help me out. The following is my code.
ImageList imageList = new ImageList();

            OpenFileDialog opend1 = new OpenFileDialog();

            opend1.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";

            opend1.Multiselect = true;

            if (opend1.ShowDialog() == DialogResult.OK)
            {

                listView1.View = View.LargeIcon;

                imageList.ImageSize = new Size(100, 100);

                for (int c = 0; c < opend1.FileNames.Length; c++)
                {

                    Image i = Image.FromFile(opend1.FileNames[c].ToString());

                    Image img = i.GetThumbnailImage(100, 100, null, new IntPtr());

                    imageList.Images.Add(img);

                }

                listView1.LargeImageList = imageList;

                for (int j = 0; j < imageList.Images.Count; j++)
                {

                    ListViewItem lstItem = new ListViewItem();

                    lstItem.ImageIndex = j;

                    listView1.Items.Add(lstItem);
                }

                listView1.Refresh();

            }



Is This A Good Question/Topic? 0
  • +

Replies To: When new image is added previous images changed in listview.

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3548
  • View blog
  • Posts: 10,986
  • Joined: 05-May 12

Re: When new image is added previous images changed in listview.

Posted 14 November 2012 - 06:20 AM

Is line 1 part of your code that is run each time you add more items to the ListView?
Was This Post Helpful? 1
  • +
  • -

#3 C#Guy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 21-February 12

Re: When new image is added previous images changed in listview.

Posted 14 November 2012 - 08:34 AM

View PostSkydiver, on 14 November 2012 - 06:20 AM, said:

Is line 1 part of your code that is run each time you add more items to the ListView?

Yes, it does run everytime I add new items to the listview.
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5475
  • View blog
  • Posts: 11,759
  • Joined: 02-June 10

Re: When new image is added previous images changed in listview.

Posted 14 November 2012 - 08:45 AM

Skydiver was pointing you to the problem. It was a hint. A gentle nudge.

Reread the question... and re-think the implications of answering 'yes'
Was This Post Helpful? 0
  • +
  • -

#5 C#Guy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 21-February 12

Re: When new image is added previous images changed in listview.

Posted 14 November 2012 - 08:23 PM

View PosttlhIn`toq, on 14 November 2012 - 08:45 AM, said:

Skydiver was pointing you to the problem. It was a hint. A gentle nudge.

Reread the question... and re-think the implications of answering 'yes'

Oh. I'm so dumb to think of it as the simple 'yes' or 'no' question. But I got it now. Thanks. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1