TopLevelDirEntriesArray() is just an array of directory entries at the top
level of the domain. Instead, you could pass in the domain name (with
Provider), then Construct a DirectoryEntry and loop on the Children:
Sub FillADTreeView(ByRef tvw as TreeView, ByVal DomainName as String)
Dim DomainEntry as New DirectoryEntry(DomainName)
Dim Nd as TreeNode
Nd = New TreeNode(DomainEntry.Name)
Nd.Tag = DomainEntry
tvw.Nodes.Add(Nd)
End Sub
Then you can basically use the same procedures I sent you before, but fill
the Domain node itself rather than the TreeView. I don't think it will work
if you only fill the top-level nodes, because they won't have an Expand sign
if they have no child nodes.... so all the user will see is a bunch of empty
nodes. However, if you're really concerned about speed, then I suggest what
you do is fill the top two levels in the AD hierarchy (i.e.
Domain\Level1Dir1\Level2Dir1), and then you can fill the nodes one level
down each time a node is expanded. For example:
Domain
Level1Dir1
Level2Dir1
Level2Dir2
Level1Dir2
Level2Dir3
All nodes at Levels 1 and 2 will be filled initially. Then, for the Expand
event of Level 1 nodes, all of its Level 2 child nodes will be filled, when
Level 2 nodes expand, Level 3 nodes will be filled, and so on. It's the
same recursion, just done at a different time:
Prive Sub tvwActiveDirectory_BeforeExpand(sender as Object, e as
TreeViewEventArgs) _
Handles tvwActiveDirectory.BeforeExpand
Dim Nd as Node
For Each Nd in e.Node 'The Expanding Node
FillADTreeNode(Nd) 'The same procedure I posted before
Next
End Sub
So, when the user clicks on the Node for Level1Dir1, the Children for the
Level2Dir1 and Level2Dir2 Nodes will be filled.
Hope this helps,
Mike
--
Michael Caputo
Programmer/Database Administrator
Simon Economic Systems Ltd.