Click here to Skip to main content
13,295,472 members (61,989 online)
Click here to Skip to main content
Add your own
alternative version


59 bookmarked
Posted 25 Apr 2004

Active Directory object picker control

, 16 May 2004
Rate this:
Please Sign up or sign in to vote.
A Windows control for selecting objects in Active Directory.

Picker control test app


A basic Windows control library for selecting objects in your Active Directory.


I've been involved in several Active Directory projects and frequently have had the need for a "picker" utility to select objects in the AD hierarchy. I decided to roll my own and encapsulate it in a Windows control library.

Sample Usage

Add the control to the list of Windows Forms controls in Visual Studio .NET, then drag the control onto a Windows Form. The control will automatically obtain your Active Directory root path and begin building a hierachal tree of the objects it finds.

private void AddTreeNodes(TreeNode node)
    Cursor.Current = Cursors.WaitCursor;
    adh = new ADHelper();
    IDictionaryEnumerator enumerator = adh.Children.GetEnumerator();

    // append children
    while (enumerator.MoveNext())
        TreeNode childNode = new TreeNode((string)enumerator.Key);
        childNode.Tag = enumerator.Value; // ADsPath

        // specific object types
        if (!alExceptions.Contains(node.Text))
            childNode.ImageIndex =
            childNode.ImageIndex = 3; // computer image
    Cursor.Current = Cursors.Default;

AddTreeNodes() takes only one parameter, the parent TreeNode object. It then proceeds to add every child object it finds. Similar to Microsoft's ADSI Edit tool, the control displays a plus sign to indicate if a node has one or more child nodes.

Returning the ADsPath

Each time a node is selected in the hierarchy, the ADsPath public property is updated to reflect the fully-qualified path to the object (i.e. LDAP://OU=DEV,OU=US,DC=CORPORATE,DC=MYDOMAIN,DC=COM).

public void GetChildEntries(string adspath)
    if (adspath.Length > 0)
        entry = new DirectoryEntry(adspath);
        entry = new DirectoryEntry();

    foreach (DirectoryEntry childEntry in entry.Children)
        _htChildren.Add(childEntry.Name, childEntry.Path);
private void treeView1_AfterSelect(object sender, 
      System.Windows.Forms.TreeViewEventArgs e)
    _adspath = (string)e.Node.Tag;


The control has been tested on Windows 2000/XP/2003. It should work for Windows 9x/NT with the Microsoft Active Directory Client Extensions installed.


  • Version 1.0 - 04.22.2004 - First release version.
  • Version 1.1 - 04.28.2004 - Added image support for object types.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Marc Merritt
United States United States
I live in beautiful Arizona, USA.

You may also be interested in...


Comments and Discussions

GeneralRe: Problems unzipping file Pin
Marc Merritt31-May-04 10:53
memberMarc Merritt31-May-04 10:53 
GeneralRe: Problems unzipping file Pin
daluu13-Mar-06 10:25
memberdaluu13-Mar-06 10:25 
GeneralProblems Unzipping the two files Pin
emi_oasis26-May-04 10:26
memberemi_oasis26-May-04 10:26 
Hello Marc Merritt,
I want to use your active directory picker tool in a project. But the
unzipping (WinAce) is giving CRC errors. Frown | :( Can you kindly check the zips
yourself. I'd be obliged if you mail em to me at
Best Regards,
Imran Shafiq.

GeneralAD Picker Pin
gmchugh28-Apr-04 22:23
membergmchugh28-Apr-04 22:23 
GeneralRe: AD Picker Pin
Marc Merritt29-Apr-04 4:38
memberMarc Merritt29-Apr-04 4:38 
GeneralRe: AD Picker Pin
Dimonytch16-May-04 22:57
memberDimonytch16-May-04 22:57 
GeneralSuggestion for TreeNode Images Pin
Heath Stewart26-Apr-04 9:18
editorHeath Stewart26-Apr-04 9:18 
GeneralRe: Suggestion for TreeNode Images Pin
olivierv27-Apr-04 1:20
sussolivierv27-Apr-04 1:20 
GeneralRe: Suggestion for TreeNode Images Pin
Marc Merritt27-Apr-04 3:16
memberMarc Merritt27-Apr-04 3:16 
GeneralRe: Suggestion for TreeNode Images Pin
Tomaž Štih18-May-04 4:06
memberTomaž Štih18-May-04 4:06 
GeneralRe: Suggestion for TreeNode Images Pin
Heath Stewart18-May-04 4:39
protectorHeath Stewart18-May-04 4:39 
GeneralRe: Suggestion for TreeNode Images Pin
Marc Merritt18-May-04 4:56
memberMarc Merritt18-May-04 4:56 
GeneralRe: Suggestion for TreeNode Images Pin
mlorr7719-May-04 2:45
membermlorr7719-May-04 2:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 17 May 2004
Article Copyright 2004 by Marc Merritt
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid