Populating Treeview from Outlook
Hi everyone.
I would like to add my email Inbox folders (and nested subfolders) to a treeview and have no clue where to begin.
I've searched online for the past couple of hours but unfortunately Google is not my friend today.
Could anyone please point me in the right direction?
Thanks in advance
Re: Populating Treeview from Outlook
Bump. Please help.
Not looking for any code (although that would be helpful), I'm just wondering where I should be looking.
Thanks folks
Re: Populating Treeview from Outlook
Re: Populating Treeview from Outlook
Thanks KG.
Don't mean to be rude, but those don't exactly answer my question. your time wasn't waisted though, because one of your links gave me the answer to something else I was trying to do.
What I'm trying to do is retrieve the Folder names in my inbox and list them in a treeview.
I finally figured it out (sort of)...
This is what I have so far but all my folders are "flat" and the SubFolders are all shown at the top level.
Code:
Private Sub AddFoldersToTree(ThisInbox As Outlook.MAPIFolder)
Dim mySbFldr As Outlook.MAPIFolder
NodeCnt = NodeCnt + 1
For Each SbFldr In ThisInbox.Folders
TreeView1.Nodes.Add(SbFldr.Name & NodeCnt, SbFldr.Name)
AddEmailFolderToTree(SbFldr, SbFldr.Name & NodeCnt)
Next SbFldr
End Sub
So for example I want my treeview to look something like this.
Code:
+Personal Inbox
-Work Inbox
|_Staff
|_Anne Jameson
|_Peter Smith
|_Steve Jones
|_Suppliers
|_Goggles
|_Kinkos
|_Retail
|_Wholesale
|_Tesco
But at the moment it's showing this
Code:
Work Inbox
Staff
Anne Jameson
Peter Smith
Steve Jones
Suppliers
Goggles
Kinkos
Retail
Wholesale
Tesco
Thanks
Re: Populating Treeview from Outlook
Hi,
Quote:
Work Inbox
Staff
Anne Jameson
Peter Smith
Steve Jones
Suppliers
Goggles
Kinkos
Retail
Wholesale
Tesco
It's flat because in this code:
vb.net Code:
For Each SbFldr In ThisInbox.Folders
TreeView1.Nodes.Add(SbFldr.Name & NodeCnt, SbFldr.Name)
AddEmailFolderToTree(SbFldr, SbFldr.Name & NodeCnt)
Next SbFldr
each node were set as parent. You need to add the other nodes as children.
Sample Code:
vb.net Code:
TrvNode = New TreeNode
TrvNode.Text= "yourtext"
TrvNode.Name= "your_name"
TreeView1.Nodes(0).Nodes(2).Nodes.Add(TrvNode)
MSDN Treeview
vb.net Code:
' Populates a TreeView control with example nodes.
Private Sub InitializeTreeView()
treeView1.BeginUpdate()
treeView1.Nodes.Add("Parent")
treeView1.Nodes(0).Nodes.Add("Child 1")
treeView1.Nodes(0).Nodes.Add("Child 2")
treeView1.Nodes(0).Nodes(1).Nodes.Add("Grandchild")
treeView1.Nodes(0).Nodes(1).Nodes(0).Nodes.Add("Great Grandchild")
treeView1.EndUpdate()
End Sub
display-hierarchical-data-in-vbnet-with-the-treeview-control/