0

如何使用 ObjectListView 显示图像列表中的所有图像?在 ObjectListView 的主页中,他们展示了如何在 C# 中执行此操作(我对 c# 和委托不太擅长)。但我无法让它在 VB.net 中工作。

4

1 回答 1

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
于 2011-12-29T14:26:44.557 回答