[英]How do I add an image to a new Listview Item?
Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader
dis = dr("Last Accessed").Substring(0, dr("Last Accessed").IndexOf(" "))
ListView1.Items.Add(New ListViewItem(New String() {docImage, dr("Id").ToString, dr("Document Name").ToString, dr("DISnummer"), dr("XPostnummer"), dis}))
I use this code to fill a listview but I like to add a little image to the left of the rows.我使用此代码填充列表视图,但我喜欢在行的左侧添加一个小图像。 I connected an imagelist but the code for adding the image doesnt work:
我连接了一个图像列表,但添加图像的代码不起作用:
If dr("[Document Type]").ToString = "PDF" Or dr("[Document Type]").ToString = "pdf" Then
docImage = (ImageList1.Images.Count - 1)
Endif
What am I doing wrong?我究竟做错了什么?
M米
After some testing I figured it out.经过一些测试,我想通了。
While dr.Read
If dr("Document Type").ToString = "PDF" Or dr("Document Type").ToString = "pdf" Then
docImage = (ImageList1.Images.Count - 1)
ElseIf dr("Document Type").ToString = "DOC" Or dr("Document Type").ToString = "doc" Then
docImage = (ImageList1.Images.Count - 3)
ElseIf dr("Document Type").ToString = "PPT" Or dr("Document Type").ToString = "ppt" Then
docImage = (ImageList1.Images.Count - 2)
End If
dis = dr("Last Accessed").Substring(0, dr("Last Accessed").IndexOf(" "))
items.Add(New ListViewItem(New String() {"", dr("Document Name").ToString, dr("DISnummer"), dr("XPostnummer"), dis, dr("Id").ToString, dr("Document Location").ToString}, docImage))
End While
The image is at the end of the items.Add function图片在项目末尾。添加 function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.