Click here to Skip to main content
11,928,786 members (45,903 online)
Click here to Skip to main content
Add your own
alternative version


59 bookmarked

Active Directory object picker control

, 16 May 2004 CPOL
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 southeastern Pennsylvania, USA with my lovely wife and two beautiful daughters. Life is good. My hobbies are motorcycles, motorcycles, and motorcycles.

I run a riders group called Twisties Motorcycle Club. If you're are a rider in the tri-state area, look us up!

You may also be interested in...

Comments and Discussions

GeneralRe: OUs are doubled Pin
sebaj24-Feb-07 5:21
membersebaj24-Feb-07 5:21 
GeneralNames ordered AD Pin
tysonx6-Jun-06 5:17
membertysonx6-Jun-06 5:17 
GeneralRe: Names ordered AD Pin
Marc Merritt12-Jun-06 3:07
memberMarc Merritt12-Jun-06 3:07 
QuestionHow can i get the selected object? Pin
rbmrf9-Mar-06 8:29
memberrbmrf9-Mar-06 8:29 
AnswerRe: How can i get the selected object? Pin
Marc Merritt9-Mar-06 8:48
memberMarc Merritt9-Mar-06 8:48 
AnswerRe: How can i get the selected object? Pin
Data-Base17-Jul-08 4:53
memberData-Base17-Jul-08 4:53 
QuestionSorted Output? Pin
VBDelinquent19-Dec-05 4:41
memberVBDelinquent19-Dec-05 4:41 
AnswerRe: Sorted Output? Pin
Marc Merritt22-Dec-05 8:00
memberMarc Merritt22-Dec-05 8:00 
GeneralHelp Using in VS2005 Pin
astocks19-Oct-05 17:50
memberastocks19-Oct-05 17:50 
GeneralRe: Help Using in VS2005 Pin
Marc Merritt20-Oct-05 2:27
memberMarc Merritt20-Oct-05 2:27 
GeneralRe: Help Using in VS2005 Pin
astocks20-Oct-05 10:48
memberastocks20-Oct-05 10:48 
GeneralRe: Help Using in VS2005 Pin
Marc Merritt20-Oct-05 12:40
memberMarc Merritt20-Oct-05 12:40 
GeneralRe: Help Using in VS2005 Pin
astocks21-Oct-05 15:17
memberastocks21-Oct-05 15:17 
QuestionSpecified domain does not exist Pin
giles papworth6-Sep-05 0:58
membergiles papworth6-Sep-05 0:58 
AnswerRe: Specified domain does not exist Pin
Marc Merritt12-Sep-05 4:48
memberMarc Merritt12-Sep-05 4:48 
GeneralRe: Specified domain does not exist Pin
Dave Midgley5-Oct-05 5:41
memberDave Midgley5-Oct-05 5:41 
GeneralRe: Specified domain does not exist Pin
Marc Merritt20-Oct-05 13:01
memberMarc Merritt20-Oct-05 13:01 
GeneralRe: Specified domain does not exist Pin
Stefan de Groot17-Apr-07 9:02
memberStefan de Groot17-Apr-07 9:02 
GeneralDisplay Pin
netman5423-Sep-04 1:30
membernetman5423-Sep-04 1:30 
GeneralPlease help me!!!! Pin
bekunkun20-Sep-04 21:51
memberbekunkun20-Sep-04 21:51 
Generalcould not add the adpicker Pin
vcorn14-Jun-04 21:38
membervcorn14-Jun-04 21:38 
GeneralProblems unzipping file Pin
lezop31-May-04 5:48
susslezop31-May-04 5:48 
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 

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.

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