2015-10-26 105 views
0

我想将一些图像显示到ListView中,但只显示图像路径/ URL。将图像添加到ListView中

这是我的代码来显示图像。

ListView1.View = View.SmallIcon 
ImageList1.ImageSize = New Size(32, 32) 
ListView1.SmallImageList = ImageList1 

ListView1.Items.Clear() 

ListView1.Items.Add("File path goes here") 

这是我第一次在ListView中显示图像,所以我真的不知道该怎么做。任何帮助,将不胜感激。谢谢。

回答

0

我假设您已经在您的ImageList1中设置图像。如果是这样,

ListView1.View = View.SmallIcon 
'ImageList1.ImageSize = New Size(32, 32) 'Not necessary 
ListView1.SmallImageList = ImageList1 
ListView1.Items.Clear() 
ListView1.Items.Add("File path goes here") 'Add 1 more parameter 

第2行是没有必要的。 而且,ListView1.Items.Add()中的1个参数是图像索引。

enter image description here

编辑:

ListView1.View = View.SmallIcon 
ImageList1.ImageSize = New Size(32, 32) 
ImageList1.Images.Clear() 
ImageList1.Images.Add("key1", New Icon("C:\Test\test.ico")) 
ListView1.SmallImageList = ImageList1 
ListView1.Items.Clear() 
ListView1.Items.Add("Text here", "key1") 
+0

您好,感谢您的建议。对此,我真的非常感激。但是,如果我删除了'ImageList1.ImageSize = New Size(32,32)',那么我的ListView将在显示的项目之间有很大的差距。我已经尝试添加索引,就像您向我展示的索引'0'一样,但结果仍然相同。我的ListView仍然显示图像url而不是图像。 – Emerald

+0

@Emerald,你的意思是你在你的代码中写了类似'ListView1.Items.Add(“C:\ Test \ test.ico”)'的东西吗?而且,你想将图标和文本动态添加到'ListView'? –

+0

是的。正确:) 如何做到这一点? – Emerald