Create a custom listViewItem class to store additional hidden info - VB .Net

我的未来我决定 提交于 2019-12-06 17:38:28

Make your Class myListboxItem inherit from ListViewItem.

I know this topic is 2 years old, but I come accross it looking for an answer. Just tried myself and it works fine with .net 2010: It might help someone :)


Public Class ListViewItemExtra
    Inherits ListViewItem
    Private _companyName As String = ""
    Private _contactPerson As String = ""
    Private _address As String = ""
    Public Property CompanyName As String
        Get
            Return _companyName
        End Get
        Set(value As String)
            _companyName = value
            Text = ToString()
        End Set
    End Property
    Public Property ContactPerson As String
        Get
            Return _contactPerson
        End Get
        Set(value As String)
            _contactPerson = value
            Text = ToString()
        End Set
    End Property
    Public Property Address As String
        Get
            Return _address
        End Get
        Set(value As String)
            _address = value
            Text = ToString()
        End Set
    End Property
    Public Overrides Function ToString() As String
        Return _companyName + " -> " & _address.Replace(vbCrLf, " ")
    End Function
    Public Function ToPrintString() As String
        Dim heading As String = ""
        If _contactPerson  "" Then
            heading = "Attention: " & _contactPerson & vbCrLf & vbCrLf
        End If
        Return heading & _companyName & vbCrLf & _address
    End Function
End Class
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!