2010-07-10 64 views
1

我試圖用海報和DVD收藏的標題填充列表視圖(瓷磚),但只有標題變得易於使用。listview瓷磚沒有顯示圖像(.NET2.0,VB,winforms)

這是我的代碼:?

Private Sub fillListView(ByVal listView As System.Windows.Forms.ListView, ByVal col As Collection) 
listView.Items.Clear() 
myImageList = New ImageList() 
For Each item As bsDVD In col 
    Try 
    myImageList.Images.Add(Image.FromFile(Application.StartupPath & item.PosterURL)) 
    Catch ex As Exception 
    MessageBox.Show(ex.message) 
    End Try 
Next 
myImageList.ImageSize = New Size(32, 32) 
listView.LargeImageList = myImageList 
For Each item As bsDVD In col 
    listView.Items.Add(item.Titel) 
Next 
End Sub 

嘗試了很多不能讓它的工作:(我都做一個愚蠢的錯誤還是希望有人能幫助我

TY提前


TY都幫了我......

解決方案代碼:

Private Sub fillListView(ByVal listView As System.Windows.Forms.ListView, ByVal col As Collection) 
listView.Items.Clear() 
myImageList = New ImageList() 
myImageList.ImageSize = New Size(70, 100) 
myImageList.ColorDepth = ColorDepth.Depth24Bit 

For Each item As bsDVD In col 
    Try 
    myImageList.Images.Add(Image.FromFile(Application.StartupPath & item.PosterURL)) 
    Catch ex As Exception 
    MessageBox.Show("Kan afbeelding niet inladen!") 
    End Try 
Next 
listView.LargeImageList = myImageList 
Dim mItem As bsDVD 
For i As Integer = 1 To col.Count 
    mItem = CType(col.Item(i), bsDVD) 
    listView.Items.Add(mItem.Titel) 
    listView.Items(i - 1).ImageIndex = (i - 1) 
Next 
End Sub 

回答

2

您需要設置listviewitem的圖像索引。

var lvitem = ListView.Items.Add(item.Titel) 
lvItem.imageIndex = 1 

ListView.Items.Add(item.Titel,1) 

第十屆項目得到的ImageIndex = X-1

此外,當視圖模式的細節,你可能需要設置其他圖像屬性(SmallImageList)。