More Informations in a TreeView

  • Thread starter Thread starter Yavuz Bogazci
  • Start date Start date
Y

Yavuz Bogazci

Hello, the following code selects recursively the Outlook folders and
shows these in a Treeview. Everything works nice. I have the following
problem:

I would like have a TreeNode a text and two more values assigned to
this TreeNode e.g. an UserID and a Text.

These two information should not be visible. But if a user selects the
TreeNode i would like to read the information of the selected
TreeNode.

How can I build that in the code below??? I read about Inheritance but
i dont know how to implement those thing in my code below. For your
assistance I would be very grateful.


Private Sub Button3_Click
' Dim Application As Outlook.Application
Dim root As TreeNode
TreeView1.Nodes.Clear()
root = TreeView1.Nodes.Add("Outlook Root")
AddChildren(root, oNS.Folders)
End Sub

Private Sub AddChildren(ByVal root As TreeNode, ByVal list As
Outlook.Folders)
Dim flr As Outlook.MAPIFolder
Dim newRoot As TreeNode
For Each flr In list
newRoot = root.Nodes.Add(flr.Name)
AddChildren(newRoot, flr.Folders)
Next flr
End Sub


thanks
yavuz bogazci
 
Yavuz Bogazci said:
Hello, the following code selects recursively the Outlook folders
and shows these in a Treeview. Everything works nice. I have the
following problem:

I would like have a TreeNode a text and two more values assigned
to this TreeNode e.g. an UserID and a Text.

These two information should not be visible. But if a user selects
the TreeNode i would like to read the information of the selected
TreeNode.

How can I build that in the code below??? I read about Inheritance
but i dont know how to implement those thing in my code below. For
your assistance I would be very grateful.
[...]

Derive your own node class from the Treenode class. In it's constructor pass
all the additional information you want to store with the node. For each
node, create a new instance of your own class.

public Class MyTreeNode
inherits TreeNode

public readonly Folder as Outlook.MAPIFolder

public sub new(Folder as Outlook.MAPIFolder)
mybase.new(folder.name)
me.folder=folder
end sub
end clss


Private Sub AddChildren(ByVal root As TreeNode, ByVal list As
Outlook.Folders)

Dim flr As Outlook.MAPIFolder
Dim newRoot As MyTreeNode

For Each flr In list
newRoot = New MyTreeNode(flr)
AddChildren(newRoot, flr.Folders)
Next flr

End Sub
 
Hi,

thank you! But there is only one Problem: I can't see the nodes! there
is no error and when i let show the name of the folders in the class
with messagebox it shows me all foldernames. but they aren't visible
in the treeview. there is no node created.

thanks
yavuz
 
Hi,

thank you! But there is only one Problem: I can't see the
nodes! there
is no error and when i let show the name of the folders
in the class
with messagebox it shows me all foldernames. but they
aren't visible
in the treeview. there is no node created.

thanks
yavuz
-----Original Message-----
Yavuz Bogazci said:
Hello, the following code selects recursively the Outlook folders
and shows these in a Treeview. Everything works nice. I have the
following problem:

I would like have a TreeNode a text and two more values assigned
to this TreeNode e.g. an UserID and a Text.

These two information should not be visible. But if a user selects
the TreeNode i would like to read the information of the selected
TreeNode.

How can I build that in the code below??? I read about Inheritance
but i dont know how to implement those thing in my code below. For
your assistance I would be very grateful.
[...]

Derive your own node class from the Treenode class. In it's constructor pass
all the additional information you want to store with the node. For each
node, create a new instance of your own class.

public Class MyTreeNode
inherits TreeNode

public readonly Folder as Outlook.MAPIFolder

public sub new(Folder as Outlook.MAPIFolder)
mybase.new(folder.name)
me.folder=folder
end sub
end clss


Private Sub AddChildren(ByVal root As TreeNode, ByVal list As
Outlook.Folders)

Dim flr As Outlook.MAPIFolder
Dim newRoot As MyTreeNode

For Each flr In list
newRoot = New MyTreeNode(flr)
AddChildren(newRoot, flr.Folders)
Next flr

End Sub
 
Ok it works!!!!!!

But how can i get now the object out of the node???????

thanks
yavuz bogazci

-----Original Message-----
Yavuz Bogazci said:
Hello, the following code selects recursively the Outlook folders
and shows these in a Treeview. Everything works nice. I have the
following problem:

I would like have a TreeNode a text and two more values assigned
to this TreeNode e.g. an UserID and a Text.

These two information should not be visible. But if a user selects
the TreeNode i would like to read the information of the selected
TreeNode.

How can I build that in the code below??? I read about Inheritance
but i dont know how to implement those thing in my code below. For
your assistance I would be very grateful.
[...]

Derive your own node class from the Treenode class. In it's constructor pass
all the additional information you want to store with the node. For each
node, create a new instance of your own class.

public Class MyTreeNode
inherits TreeNode

public readonly Folder as Outlook.MAPIFolder

public sub new(Folder as Outlook.MAPIFolder)
mybase.new(folder.name)
me.folder=folder
end sub
end clss


Private Sub AddChildren(ByVal root As TreeNode, ByVal list As
Outlook.Folders)

Dim flr As Outlook.MAPIFolder
Dim newRoot As MyTreeNode

For Each flr In list
newRoot = New MyTreeNode(flr)
AddChildren(newRoot, flr.Folders)
Next flr

End Sub
 
Yavuz Bogazci said:
Ok it works!!!!!!

But how can i get now the object out of the node???????

For example, in the AfterSelect event:

dim MyNode as MyTreeNode
mynode = directcast(e.node, MyTreenode)

msgbox mynode.folder.name
 
Back
Top