vb.net 使用Listview在vb中在一列中插入图像并在另一列中写入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33873100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 19:35:22  来源:igfitidea点击:

Using Listview to insert an image in one column and write in another in vb

vb.netimagewinformslistview

提问by Satvir Singh

I have a listview with three column named: picture, time, description. I need to add an image to the first column and at then add time and description to the other but in the same row.

我有一个名为三列的列表视图:图片、时间、描述。我需要将图像添加到第一列,然后在同一行中向另一列添加时间和描述。

I had a look on the internet and managed to find a code that adds the images to the listview. This is shown below:

我在互联网上查看并设法找到将图像添加到列表视图的代码。这如下所示:

Dim imagelist As ImageList = New ImageList()
imagelist.ImageSize = New Size(10, 10)

imagelist.Images.Add(Bitmap.FromFile("0.png"))
imagelist.Images.Add(Bitmap.FromFile("1.png"))
imagelist.Images.Add(Bitmap.FromFile("2.png"))
imagelist.Images.Add(Bitmap.FromFile("3.png"))
imagelist.Images.Add(Bitmap.FromFile("4.png"))
imagelist.Images.Add(Bitmap.FromFile("5.png"))
LV_Log.Items.Add("", 5)
LV_Log.SmallImageList = imagelist

Now I have a code that added text to the columns.

现在我有一个向列添加文本的代码。

Dim lvi As New ListViewItem
lvi.Text = "image"
lvi.SubItems.Add(Now())
lvi.SubItems.Add(message)
LV_Log.Items.Add(lvi)

Here I want to add an image where it says "image".

在这里,我想添加一个显示“图像”的图像。

回答by Ryan Thomas

Assuming the ListView's imageList property is set to the correct image list you can do something like this.

假设 ListView 的 imageList 属性设置为正确的图像列表,您可以执行以下操作。

Dim newItem As ListViewItem = New ListViewItem
newItem.ImageIndex = 0 'or look for correct one from image list
newItem.SelectedImageIndex = 0 'if the image should change
newItem.Text = Now()
newItem.SubItems.Add("description") 'may need to play here, haven't done this in a while