0

我有这个ListView,我想将图像加载到那个ListView。我有存储图像的文件路径。我想循环文件路径中包含的每个图像并将它们加载到列表视图中。而且我不知道该怎么做。你能帮帮我吗?以下是我未完成的代码。谢谢你。

DataTable dtPath = new DataTable();
dtPath = ContrPtMRD.SelectFilePaths();

foreach (DataRow rows in dtPath.Rows)
{
    lvPtMedicalRecord.????
}
4

1 回答 1

4

看来您将其存储Image locations在同一个 DataTable 中。如果您ImageList在处理 foreach 循环的同时存储这些图像位置,那将是可以理解的。这是示例代码:

lvPtMedicalRecord.LargeImageList = myImageList;  //Attaching ImageList to the ListView
int imageIndex = 0;
foreach (DataRow rows in dtPath.Rows)
{
   //Store the paths of the images in the same DataTable (I can think of this only)
   myImageList.Images.Add(Image.FromFile(row[0].ToString());
   ListViewItem lvi = new ListViewItem();
   lvi.ImageIndex = imageIndex; //Index of the Image present in the `ImageList`
   imageIndex++;
   lvPtMedicalRecord.Items.Add(lvi);
}

更新:

为了使图像变大:

 myImageList.ImageSize = new System.Drawing.Size(112, 112); // width, height
于 2012-11-17T05:47:44.733 回答