开发者

listview tiles not showing images (.NET2.0 , VB , winforms)

Im trying to fill a listview(tiles) with posters and titles of a DVD collection but only the titles become vissible.

this is my code:

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

Tried a lot cant get it working:(. Did i mak开发者_如何学Pythone a stupid mistake or? hope someone can help me.

ty in advance


ty both for helping me out...

solution code:

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


You need to set the imageindex of the listviewitem.

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

or

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

The Xth item gets imageindex = x-1

Also, when viewmode is details, you might need to set the other Images property (SmallImageList).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜