Can't get email folder names using IMAPX

176 Views Asked by At

I am using this code to get the list of email folders :

Class emailFolder
    Public Property Title As String
End Class

Public Shared Function GetFolders() As List(Of emailFolder)
    Dim folder = New List(Of emailFolder)
    Dim foldername = client.Folders
    For Each parentFolder In foldername
        Dim parentPath = parentFolder.Path
        If parentFolder.HasChildren Then
            Dim subfolders = parentFolder.SubFolders
            For Each subfolder In subfolders
                Dim subPath = subfolder.Path
                folder.Add(New emailFolder With {.Title = parentFolder.Name})
            Next
        End If
    Next
    Return folder
End Function

Public sub btn_click handles Button1.click

ListView.ItemSource=GetFolders 

I dunno what is wrong with my code but the items I get in the ListView (I'm in wpf by the way) look like this :

 MyApplication++emailfolder
 MyApplication++emailfolder
 MyApplication++emailfolder
 MyApplication++emailfolder

What am I doing wrong ?

2

There are 2 best solutions below

2
Aousaf Rashid On BEST ANSWER

The problem was solved..Thanks for the comments guys!!

Just had to override the ToString....Full code:

   Class emailFolder
    Public Property Title As String
   Public Overrides Function ToString() As String
            Return Me.Title
        End Function
End Class

  Public Shared Function GetFolders() As List(Of emailFolder)
    Dim folder = New List(Of emailFolder)
    Dim foldername = client.Folders
    For Each parentFolder In foldername
        Dim parentPath = parentFolder.Path
        If parentFolder.HasChildren Then
            Dim subfolders = parentFolder.SubFolders
            For Each subfolder In subfolders
                Dim subPath = subfolder.Path
                folder.Add(New emailFolder With {.Title = parentFolder.Name})
            Next
        End If
    Next
    Return folder
End Function

Public sub btn_click handles Button1.click

ListView.ItemSource=GetFolders 
1
MatSnow On

If you define the ItemTemplate of the ListView, you can define how the ListViewItems should look like.

With the following example just the content of the property Title will be displayed:

<ListView>
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Title}" />
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Another approach is to add an override of the ToString-method to the emailFolder-class:

Class emailFolder
    Public Property Title As String

    Public Overrides Function ToString() As String
        Return Me.Title
    End Function
End Class