G
Guest
I have very limited knowledge of VB and am trying to convert this to list
Just OU then when selected fill a text box with the full DN. I know this is a
big ask but can anyone help.
I know i need a filter to filter on Just OU.
The code i have thus far is:
Private Sub subRootNode()
Try
dBase = New DirectoryEntry("LDAP://" & DomainName())
Dim oRootNode As TreeNode = Me.treeviewOU.Nodes.Add(dBase.Path)
oRootNode.ImageIndex = 0
oRootNode.SelectedImageIndex = 0
oRootNode.Tag = dBase
oRootNode.Text = dBase.Name.Substring(3)
oRootNode.Nodes.Add("")
Catch ex As Exception
MessageBox.Show("Cannot create initial node: " & ex.ToString)
End
End Try
End Sub
Private Sub treeviewOU_BeforeExpand(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewCancelEventArgs) Handles treeviewOU.BeforeExpand
Windows.Forms.Cursor.Current = Cursors.WaitCursor
If e.Node.ImageIndex > 3 Then Exit Sub
Try
If e.Node.GetNodeCount(False) = 1 And e.Node.Nodes(0).Text = ""
Then
e.Node.Nodes(0).Remove()
subEnumerateChildren(e.Node)
End If
Catch ex As Exception
MessageBox.Show("Unable to expand " & e.Node.FullPath & ":" &
ex.ToString)
End Try
If e.Node.GetNodeCount(False) > 0 Then
e.Node.ImageIndex = 1
e.Node.SelectedImageIndex = 1
End If
Windows.Forms.Cursor.Current = Cursors.Default
End Sub
Private Sub subEnumerateChildren(ByVal oRootNode As TreeNode)
Dim deParent As DirectoryEntry = DirectCast(oRootNode.Tag,
DirectoryEntry)
For Each deChild As DirectoryEntry In deParent.Children
Dim oChildNode As TreeNode = oRootNode.Nodes.Add(deChild.Path)
Select Case deChild.SchemaClassName
Case "computer"
oChildNode.ImageIndex = 4
oChildNode.SelectedImageIndex = 4
Case "user"
oChildNode.ImageIndex = 5
oChildNode.SelectedImageIndex = 5
Case "group"
oChildNode.ImageIndex = 6
oChildNode.SelectedImageIndex = 6
Case "organizationalUnit"
oChildNode.ImageIndex = 0
oChildNode.SelectedImageIndex = 0
oChildNode.Nodes.Add("")
Case "container"
oChildNode.ImageIndex = 0
oChildNode.SelectedImageIndex = 0
oChildNode.Nodes.Add("")
Case "publicFolder"
oChildNode.ImageIndex = 3
oChildNode.SelectedImageIndex = 3
oChildNode.Nodes.Add("")
Case Else
oChildNode.ImageIndex = 2
oChildNode.SelectedImageIndex = 2
oChildNode.Nodes.Add("")
End Select
oChildNode.Tag = deChild
oChildNode.Text = deChild.Name.Substring(3).Replace("\", "")
Next
End Sub
Private Sub treeviewOU_BeforeCollapse(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewCancelEventArgs) Handles
treeviewOU.BeforeCollapse
e.Node.ImageIndex = 0
e.Node.SelectedImageIndex = 0
End Sub
Just OU then when selected fill a text box with the full DN. I know this is a
big ask but can anyone help.
I know i need a filter to filter on Just OU.
The code i have thus far is:
Private Sub subRootNode()
Try
dBase = New DirectoryEntry("LDAP://" & DomainName())
Dim oRootNode As TreeNode = Me.treeviewOU.Nodes.Add(dBase.Path)
oRootNode.ImageIndex = 0
oRootNode.SelectedImageIndex = 0
oRootNode.Tag = dBase
oRootNode.Text = dBase.Name.Substring(3)
oRootNode.Nodes.Add("")
Catch ex As Exception
MessageBox.Show("Cannot create initial node: " & ex.ToString)
End
End Try
End Sub
Private Sub treeviewOU_BeforeExpand(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewCancelEventArgs) Handles treeviewOU.BeforeExpand
Windows.Forms.Cursor.Current = Cursors.WaitCursor
If e.Node.ImageIndex > 3 Then Exit Sub
Try
If e.Node.GetNodeCount(False) = 1 And e.Node.Nodes(0).Text = ""
Then
e.Node.Nodes(0).Remove()
subEnumerateChildren(e.Node)
End If
Catch ex As Exception
MessageBox.Show("Unable to expand " & e.Node.FullPath & ":" &
ex.ToString)
End Try
If e.Node.GetNodeCount(False) > 0 Then
e.Node.ImageIndex = 1
e.Node.SelectedImageIndex = 1
End If
Windows.Forms.Cursor.Current = Cursors.Default
End Sub
Private Sub subEnumerateChildren(ByVal oRootNode As TreeNode)
Dim deParent As DirectoryEntry = DirectCast(oRootNode.Tag,
DirectoryEntry)
For Each deChild As DirectoryEntry In deParent.Children
Dim oChildNode As TreeNode = oRootNode.Nodes.Add(deChild.Path)
Select Case deChild.SchemaClassName
Case "computer"
oChildNode.ImageIndex = 4
oChildNode.SelectedImageIndex = 4
Case "user"
oChildNode.ImageIndex = 5
oChildNode.SelectedImageIndex = 5
Case "group"
oChildNode.ImageIndex = 6
oChildNode.SelectedImageIndex = 6
Case "organizationalUnit"
oChildNode.ImageIndex = 0
oChildNode.SelectedImageIndex = 0
oChildNode.Nodes.Add("")
Case "container"
oChildNode.ImageIndex = 0
oChildNode.SelectedImageIndex = 0
oChildNode.Nodes.Add("")
Case "publicFolder"
oChildNode.ImageIndex = 3
oChildNode.SelectedImageIndex = 3
oChildNode.Nodes.Add("")
Case Else
oChildNode.ImageIndex = 2
oChildNode.SelectedImageIndex = 2
oChildNode.Nodes.Add("")
End Select
oChildNode.Tag = deChild
oChildNode.Text = deChild.Name.Substring(3).Replace("\", "")
Next
End Sub
Private Sub treeviewOU_BeforeCollapse(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewCancelEventArgs) Handles
treeviewOU.BeforeCollapse
e.Node.ImageIndex = 0
e.Node.SelectedImageIndex = 0
End Sub