【问题标题】:How to load images into listview如何将图像加载到列表视图中
【发布时间】:2012-11-17 14:50:46
【问题描述】:

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

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

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

【问题讨论】:

  • 检查一下:msdn forum post 提供了您可能需要的帮助。 :)
  • @Mr_Green 如何使列表视图中的图像看起来更大?我尝试更改lvPtMedicalRecord.LargeImageList = myImageList;,但图像仍然很小。
  • 首先你的图片默认应该很大。如果它们很大,请尝试ImageList.ImageSize 属性。
  • 甚至更改 View 属性也可以。

标签: c# image listview


【解决方案1】:

您似乎将Image locations 存储在同一个数据表中。如果在处理 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

【讨论】:

    猜你喜欢
    • 2011-04-07
    • 1970-01-01
    • 2016-10-05
    • 1970-01-01
    • 2018-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多