473,800 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3583
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.Director yServices
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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'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.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.components = New System.Componen tModel.Containe r
Dim resources As System.Resource s.ResourceManag er = New
System.Resource s.ResourceManag er(GetType(Form 1))
Me.TreeView1 = New System.Windows. Forms.TreeView
Me.ImageList1 = New System.Windows. Forms.ImageList (Me.components)
Me.SuspendLayou t()
'
'TreeView1
'
Me.TreeView1.Im ageList = Me.ImageList1
Me.TreeView1.Lo cation = New System.Drawing. Point(32, 24)
Me.TreeView1.Na me = "TreeView1"
Me.TreeView1.Si ze = New System.Drawing. Size(240, 248)
Me.TreeView1.Ta bIndex = 0
'
'ImageList1
'
Me.ImageList1.I mageSize = New System.Drawing. Size(16, 16)
Me.ImageList1.I mageStream =
CType(resources .GetObject("Ima geList1.ImageSt ream"),
System.Windows. Forms.ImageList Streamer)
Me.ImageList1.T ransparentColor = System.Drawing. Color.Transpare nt
'
'Form1
'
Me.AutoScaleBas eSize = 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 DirectorySearch er(root)
Dim s As SearchResult
Dim nodearr() As TreeNode
searcher.Search Scope = SearchScope.One Level
Dim I As Integer
Dim cp As IComparer
cp = New NodeComparer

ReDim nodearr(searche r.FindAll.Count - 1)

For Each s In searcher.FindAl l
Dim no As New
TreeNode(s.GetD irectoryEntry.P roperties("Name ").Value.ToStri ng,
GetObjectClass( s.GetDirectoryE ntry.Properties ("Distinguished Name").Value.To String),
GetObjectClass( s.GetDirectoryE ntry.Properties ("Distinguished Name").Value.To String))
no.Tag =
s.GetDirectoryE ntry.Properties ("Distinguished Name").Value.To String
nodearr(I) = no

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

Dim k As TreeNode
TreeView1.Nodes .AddRange(nodea rr)

End Sub

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
GetOU()

End Sub

Private Sub TreeView1_Doubl eClick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles TreeView1.Doubl eClick

If TreeView1.Selec tedNode.GetNode Count(True) < 1 Then
Dim root As New DirectoryEntry( "LDAP://" &
TreeView1.Selec tedNode.Tag.ToS tring)
Dim searcher As New DirectorySearch er(root)
Dim s As SearchResult
Dim nodearr As TreeNode()
searcher.Search Scope = SearchScope.One Level
Dim I As Integer
Dim cp As IComparer
cp = New NodeComparer

ReDim nodearr(searche r.FindAll.Count - 1)

For Each s In searcher.FindAl l
Dim no As New
TreeNode(s.GetD irectoryEntry.P roperties("Name ").Value.ToStri ng,
GetObjectClass( s.GetDirectoryE ntry.Properties ("Distinguished Name").Value.To String),
GetObjectClass( s.GetDirectoryE ntry.Properties ("Distinguished Name").Value.To String))
no.Tag =
s.GetDirectoryE ntry.Properties ("Distinguished Name").Value.To String
nodearr(I) = no
I += 1
Next
Array.Sort(node arr, cp)
TreeView1.Selec tedNode.Nodes.A ddRange(nodearr )
TreeView1.Selec tedNode.Expand( )
End If

End Sub

Private Function GetRootDSE() As String

Dim RootEntry As New DirectoryEntry( "LDAP://RootDSE")
Return RootEntry.Prope rties("DefaultN amingContext"). 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 "organizational Unit"
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.Compa re
Return CType(x, TreeNode).Image Index - CType(y, TreeNode).Image Index

End Function
End Class
"Director - Minvent" <Di************ *@discussions.m icrosoft.com> wrote in
message news:D1******** *************** ***********@mic rosoft.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
10825
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 can this be done?
0
2182
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 am able to check using xpath in asp.net 2.0 till MenuItem node. if i check visible attribute value till SubMenuLevel0 node then in tree it will not display the MenuItem Node at all Note: My tree Menu will start from MenuItem node and it will...
1
4913
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 view is big largely big enough to fit the nodes and text. If I widen the tree view the scroll bar doesn't resize itself to show the relative view size in relation to the total size. Only if I narrow the view to not fit the nodes, the scroll box...
3
6062
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 hierarchical view of Parent Nodes and projects where in a projectnode can be added to any ParentNode and hence we may have a project node added to 100 Parent nodes. In this one, I have an operation of Renaming a Project Node. So whenever I am doing the...
1
2179
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 the HTREEITEMs are not updating properly. This is espeically true if I update the size of an individual HTREEITEM more than once -- making it larger, and then smaller again. The tree view's scroll bar no longer works correctly -- it doesn't scroll...
10
2533
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 for ASP.NET however most of them are already compiled and don't come with source code. I am really just looking for an example on how to create my own Tree Control. Thanks a bunch.
0
1432
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 to have nodes for all pages in the website. However it seems that I cannot create child nodes within this tree view for pages that exist outside the Admin folder.(i.e.pags within the User folder or the Root folder ).It gives me an errors stating...
3
2378
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 page by keeping the tree structure in master page. Note: tree structure is created success fully. Now i want it display the output in the iframe which is besides the tree structure. That tree structure should display in every page with out hard...
1
4804
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 view,but i want to add a new node on that tree. i select a node location in a dropdown control(nodes present in a tree will appear in this control). i will give the new node name in a text box control. when i press a button in my html page
1
2615
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 looking to polpulate tree view selectively.Only populating those nodes that user expands it by reading xml file.Can any one plz help me with some suggestions or point out to some sample code(it would be better) on how can i accomplish this.Thank in...
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10504
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10274
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9085
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.