我在顯示列表視圖中的圖標時遇到困難。 我試過這段代碼,但沒有任何反應。Listview圖標不顯示
Dim imageList1 As ImageList
imageList1 = New ImageList()
imageList1.Images.Add(Bitmap.FromFile("C:\Users\Documents\Visual Studio 2012\Projects\MYPS\MYPSApp (client-local.vbp)\Images\UserListview.ico"))
mvarListView.SmallImageList = imageList1
其實,我不想上面的代碼,因爲它確實是硬編碼的。 我想要的是: 在我的列表視圖中,有一個名爲「SmallImageList」的屬性。 單擊該屬性圖像的集合給我一個0-27的圖像列表。 (見圖片)
Collection of Images in Designer
我想顯示的是#27圖標列表視圖我的左邊,怎麼樣?
Dim clmX As System.Windows.Forms.ColumnHeader
Dim itmX As System.Windows.Forms.ListViewItem
mvarListView.View = System.Windows.Forms.View.Details
mvarListView.MultiSelect = False
mvarListView.GridLines = True
mvarListView.LabelEdit = False
mvarListView.Columns.Clear()
mvarListView.Items.Clear()
itmX = mvarListView.Items.Add("")
On Error Resume Next
'UPGRADE_ISSUE: MSComctlLib.ListItem property itmX.SmallIcon was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
itmX.Selected = CShort(listnode.selectSingleNode("icon").nodeTypedValue)
' itmX.ImageKey = CShort(listnode.selectSingleNode("icon").nodeTypedValue)
**itmX.ImageKey = 27** '<-- not working :(
itmX.Text = CStr(listnode.selectSingleNode("text").nodeTypedValue)
itmX.Tag = listnode.selectSingleNode("type").nodeTypedValue
subitemnodes = listnode.selectNodes("subitem")
For i = 1 To columncount - 1
'UPGRADE_WARNING: Lower bound of collection itmX has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
If itmX.SubItems.Count > i Then
itmX.SubItems(i).Text = CStr(subitemnodes(i - 1).nodeTypedValue)
Else
itmX.SubItems.Insert(i, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, CStr(subitemnodes(i - 1).nodeTypedValue)))
End If
Next
請幫忙。
感謝, 佑
'itmX.ImageIndex = 27'很難想象如果你嘗試了任何東西,你會錯過intellisense – Plutonix
你是什麼意思呢想念intellisense?這是輸出,它沒有在我的列表視圖左邊的任何圖標..(見頂部圖片) –
[智能感知](http://i.imgur.com/VB9p1YG.jpg) – Plutonix