我有ListView
,我想将图片加载到ListView
。我有文件路径存储图像。我想循环文件路径中包含的每个图像并将它们加载到listview中。我不知道该怎么做。你能帮帮我吗?以下是我未完成的代码。谢谢。
DataTable dtPath = new DataTable();
dtPath = ContrPtMRD.SelectFilePaths();
foreach (DataRow rows in dtPath.Rows)
{
lvPtMedicalRecord.????
}
答案 0 :(得分:3)
您似乎将Image locations
存储在同一个DataTable中。如果您在处理foreach循环时将这些图像位置存储在ImageList
中,这将是可以理解的。以下是示例代码:
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