To add objects to your listbox’s item collection you need to do the following.

Public Class EmailItem
    Private _email As Chilkat.Email

    Public Sub New(ByVal Email As Chilkat.Email)
        _email = Email
    End Sub

    Public Property ChilkatEmail() As Chilkat.Email
        Get
            Return _email
        End Get
        Set(ByVal Value As Chilkat.Email)
            _email = Value
        End Set
    End Property

    'Very important.  This is what will show in the list box when
    'you add the object.
    'if you do not override the ToString method
    'the name of the object will show in the list box
    Public Overrides Function ToString() As String
        'This can be whatever you want to show in the listbox
        Return _email.Subject
    End Function
End Class

...
'Add new item
lstMails.Items.Add(New EmailItem(email))
...

...
'Get ChilkaEmail OBject
CType(lstMails.SelectedItem, EmailItem).ChilkatEmail
...
Advertisements