0

I am scanning the images via WIA and saving the images in List. What I want is, I want to save the get the images from the list and show them in the listview. But I am getting a strange problem. When I click Scan button in my c# window application my list saves only latest image and my List counter doesn't increases to 2 it always remains 1. So my list only save the latest image and overwrite the previous image. Here is my code when I click Scan Button:

            List<Image> images = WIAScanner.Scan((string)lbDevices.SelectedItem);
            ImageList imageList1 = new ImageList();

            foreach (Image image in images)
            {
                pictureBox.Image = image;

                imageList1.Images.Add(image);

            }

                this.listView1.View = View.LargeIcon;
                imageList1.ImageSize = new Size(90, 90);
                listView1.LargeImageList = imageList1;

                for (int j = 0; j < imageList1.Images.Count; j++)
                {
                    ListViewItem item = new ListViewItem();
                    item.ImageIndex = j;
                    this.listView1.Items.Add(item);
                }
Fahad Murtaza
  • 256
  • 2
  • 9
  • 18

1 Answers1

1

I suppose the code you posted, is the code which is lying behind your scan button's click event. If so, put the following line out of the click event.

ImageList imageList1 = new ImageList();

With this line you will reset your ImageList, everytime you start a new scan. Put this line outside your click method and all should be fine.

netblognet
  • 1,951
  • 2
  • 20
  • 46
  • yup it works! but having another problem now. it is now doubling thw images because of this line imageList1.Images.Add(image); while looping – Fahad Murtaza Jul 04 '13 at 12:17
  • Put a `this.listView1.Items.Clear();` before the "for-loop" where you fill your list. ;) Would you please accept my answer. ;) – netblognet Jul 04 '13 at 12:27