473,396 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

tree view

Hi,

I am trying to work out the easiest way to add some things to a treeview.

I have got a list of the priviliged names for each of the computers e.g.

LDAP://DomainName/CN=ComputerName,OU=OrgUnit1,OU=OrgUnit2,
DC=DCRecord1,DC=DCRecord2

I am iterating through a list of these names to split them into strings for
the domain name and common name and an arraylist of strings for the
organisational units.

That bit works fine no problems, The problem I have is that on a one by one
basis I need to add them onto the correct node of the treeview taking account
the current structure of domains and OU's in the tree view and not
reproducing nodes that are already present.

Hope that makes sense!

Thanks M
--
If at first you don't succeed... Hide the evidence that you tried!
Nov 21 '05 #1
1 3560
Hi,

I started off a project to build my own "AD explorer", and think your are
after something similar. The code below build a treeview representation of
AD. See if this gives you some help

Regards

Niclas

Imports System.DirectoryServices
Public Class Form1

Inherits System.Windows.Forms.Form
Private sRootDSE As String
#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
sRootDSE = GetRootDSE()
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(Form1))
Me.TreeView1 = New System.Windows.Forms.TreeView
Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
Me.SuspendLayout()
'
'TreeView1
'
Me.TreeView1.ImageList = Me.ImageList1
Me.TreeView1.Location = New System.Drawing.Point(32, 24)
Me.TreeView1.Name = "TreeView1"
Me.TreeView1.Size = New System.Drawing.Size(240, 248)
Me.TreeView1.TabIndex = 0
'
'ImageList1
'
Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
Me.ImageList1.ImageStream =
CType(resources.GetObject("ImageList1.ImageStream" ),
System.Windows.Forms.ImageListStreamer)
Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(552, 302)
Me.Controls.Add(Me.TreeView1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region
Sub GetOU()
Dim root As New DirectoryEntry("LDAP://" & sRootDSE)
Dim searcher As New DirectorySearcher(root)
Dim s As SearchResult
Dim nodearr() As TreeNode
searcher.SearchScope = SearchScope.OneLevel
Dim I As Integer
Dim cp As IComparer
cp = New NodeComparer

ReDim nodearr(searcher.FindAll.Count - 1)

For Each s In searcher.FindAll
Dim no As New
TreeNode(s.GetDirectoryEntry.Properties("Name").Va lue.ToString,
GetObjectClass(s.GetDirectoryEntry.Properties("Dis tinguishedName").Value.ToString),
GetObjectClass(s.GetDirectoryEntry.Properties("Dis tinguishedName").Value.ToString))
no.Tag =
s.GetDirectoryEntry.Properties("DistinguishedName" ).Value.ToString
nodearr(I) = no

I += 1
Next
Array.Sort(nodearr, cp)

Dim k As TreeNode
TreeView1.Nodes.AddRange(nodearr)

End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
GetOU()

End Sub

Private Sub TreeView1_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TreeView1.DoubleClick

If TreeView1.SelectedNode.GetNodeCount(True) < 1 Then
Dim root As New DirectoryEntry("LDAP://" &
TreeView1.SelectedNode.Tag.ToString)
Dim searcher As New DirectorySearcher(root)
Dim s As SearchResult
Dim nodearr As TreeNode()
searcher.SearchScope = SearchScope.OneLevel
Dim I As Integer
Dim cp As IComparer
cp = New NodeComparer

ReDim nodearr(searcher.FindAll.Count - 1)

For Each s In searcher.FindAll
Dim no As New
TreeNode(s.GetDirectoryEntry.Properties("Name").Va lue.ToString,
GetObjectClass(s.GetDirectoryEntry.Properties("Dis tinguishedName").Value.ToString),
GetObjectClass(s.GetDirectoryEntry.Properties("Dis tinguishedName").Value.ToString))
no.Tag =
s.GetDirectoryEntry.Properties("DistinguishedName" ).Value.ToString
nodearr(I) = no
I += 1
Next
Array.Sort(nodearr, cp)
TreeView1.SelectedNode.Nodes.AddRange(nodearr)
TreeView1.SelectedNode.Expand()
End If

End Sub

Private Function GetRootDSE() As String

Dim RootEntry As New DirectoryEntry("LDAP://RootDSE")
Return RootEntry.Properties("DefaultNamingContext").Value .ToString
'Add error handling
End Function

Private Function GetObjectClass(ByVal DN As String) As Integer
Dim m As New DirectoryEntry("LDAP://" & DN)
Dim r As New DirectoryEntry(m.NativeObject.schema.ToString)

Select Case r.Name
Case "organizationalUnit"
Return 0
Case "computer"
Return 1
Case "user"
Return 2
Case Else
Return 0
End Select
End Function

End Class
Class NodeComparer
Implements IComparer 'Implement the IComparer Interface
Overloads Function Compare(ByVal x As Object, ByVal y As Object) As
Integer Implements IComparer.Compare
Return CType(x, TreeNode).ImageIndex - CType(y, TreeNode).ImageIndex

End Function
End Class
"Director - Minvent" <Di*************@discussions.microsoft.com> wrote in
message news:D1**********************************@microsof t.com...
Hi,

I am trying to work out the easiest way to add some things to a treeview.

I have got a list of the priviliged names for each of the computers e.g.

LDAP://DomainName/CN=ComputerName,OU=OrgUnit1,OU=OrgUnit2,
DC=DCRecord1,DC=DCRecord2

I am iterating through a list of these names to split them into strings
for
the domain name and common name and an arraylist of strings for the
organisational units.

That bit works fine no problems, The problem I have is that on a one by
one
basis I need to add them onto the correct node of the treeview taking
account
the current structure of domains and OU's in the tree view and not
reproducing nodes that are already present.

Hope that makes sense!

Thanks M
--
If at first you don't succeed... Hide the evidence that you tried!

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: imani_technology_spam | last post by:
We need to present hierarchical data on a web page, the same way the tree view shows files in Windows Explorer. Here's the catch: that tree view needs to be bound to a SQL Server database. How...
0
by: Tree menu using XML | last post by:
I have one XML file that has nodes and sub node and each and every node has the attribute call visible if its value is true then diplay this node else don't display thid node, but this condition i...
1
by: Jesper DK | last post by:
Hi, I have docked a tree view to the left on a form. When I start to populate this tree view with nodes, a horizontal scroll box appears in the bottom of the tree view even though thee tree...
3
by: Saradhi | last post by:
Hi All, Here I am facing a performance problem with the TreeView Node renaming. I am displaying a hierarchy Data in a treeview in my Windows C# Application. My tree view represents an...
1
by: Kaye | last post by:
It seems that when I dynamically resize items in a tree-view control, using TVM_SETITEM and the TVITEMEX iIntegral member, things go awry. The window draws properly, but it seems like the RECTs for...
10
by: dwok | last post by:
Does anyone know of a good article that discusses creating a "Tree View" control in ASP.NET? Or perhaps a Tree View Control that comes with source code? I have come across a lot of tree controls...
0
by: rinishrk | last post by:
Hi, I have a web application that contains subfolders Admin and User with related webpages inside them. Within the Admin folder I have a page containing a Tree View Control.I want this tree view...
3
by: gmail | last post by:
Hi Friends, Can any body suggest me on this. I am working on .NET 2005 Frame work 2.0 . I am facing problem using the tree stucture. I created the site map.Now i want use the site map in every...
1
by: BeginingOfLife | last post by:
i am using a java script to create a tree view in my html page. i got that script from this link : http://destroydrop.com/javascripts/tree/ given script is static script creations for tree...
1
by: happy.john1234 | last post by:
Hi, i have got large xml file which i have to show in tree view windows form.I tried with loading all those data at once to tree view but it took a long time to render that tree view.Now i am...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.