如何使用ObjectListView显示图像列表中的所有图像?

时间:2011-12-29 14:02:01

标签: vb.net imagelist objectlistview

如何使用ObjectListView显示图像列表中的所有图像?在ObjectListView的主站点中,他们已经展示了如何在C#中执行此操作(我对c#和委托不太好)。但我不能让它在VB.net中运行。

1 个答案:

答案 0 :(得分:2)

以下是他们的例子的直接翻译:

Me.mainColumn.ImageGetter = Function(row As Object) Do
    Dim key As String = Me.GetImageKey(row)
    If Not Me.listView.LargeImageList.Images.ContainsKey(key) Then
        Dim smallImage As Image = Me.GetSmallImageFromStorage(key)
        Dim largeImage As Image = Me.GetLargeImageFromStorage(key)
        Me.listView.SmallImageList.Images.Add(key, smallImage)
        Me.listView.LargeImageList.Images.Add(key, largeImage)
    End If
    Return key
End Function

这只适用于最新版本的VB.NET,因为它使用内联函数。对于旧版本,您可以像这样更改它:

创建类似于:

的功能
Public Function GetImageFromList(row As Object) As String
        Dim key As String = Me.GetImageKey(row)
        If Not Me.listView.LargeImageList.Images.ContainsKey(key) Then
            Dim smallImage As Image = Me.GetSmallImageFromStorage(key)
            Dim largeImage As Image = Me.GetLargeImageFromStorage(key)
            Me.listView.SmallImageList.Images.Add(key, smallImage)
            Me.listView.LargeImageList.Images.Add(key, largeImage)
        End If
        Return key
End Function

然后将列的图像获取器设置为:

Me.mainColumn.ImageGetter = AddressOf GetImageFromList