我对列表视图很陌生。我正在尝试在列表视图中显示图像。当我添加新项目时,所有以前的项目都会更改为新项目。所以列表视图具有相同的图像。我已经完成了谷歌搜索,但仍然找不到解决方案。请帮帮我。以下是我的代码。
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();
}