select node in treeview

G

Guest

Hallo!

I'm filling my treenode tv with AD-infos with the following code:
____________________________________________________________________
private enum AdImages
{
AdRoot,
Ou,
Container,
OpenContainer,
Computer,
User,
Group,
Unknown,
Unavailable
}
private DirectoryEntry _AdRootDSE = null;
private DirectoryEntry _AdRoot = null;

try
{
this._AdRootDSE = new DirectoryEntry(@"LDAP://rootDSE");
this._AdRoot = new DirectoryEntry("LDAP://" + (string)

this._AdRootDSE.Properties["defaultNamingContext"].Value);
TreeNode root = new TreeNode((string)this._AdRootDSE.Properties
["defaultNamingContext"].Value,
(int)AdImages.AdRoot,
(int)AdImages.AdRoot);
root.Tag = this._AdRoot;
this.tV.Nodes.Clear();
this.tV.Nodes.Add(root);
this.tV.ExpandAll();
}
catch
{
throw new Exception("Error connecting to AD");
}
____________________________________________________________________

Now I would like to select a single node in the treeview. I've got the info
which one stored in a string like this: "OU=Testunit,DC=Domain,DC=local".
How can I select this one? I've tried a lot of things but nothing works. Can
anyone help me please?

Thanks in advance!!!
 
K

Kevin Yu [MSFT]

Hi Martin,

To select a node in the TreeView, you can use TreeView.SelectedNode
property to set the current selected node in the controls. It must be a
node in the TreeView's Nodes tree.

Please check the following link for more information:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.treeview.selec
tednode.aspx

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

Hallo Kevin,

thanks for your answer. I know this article, but it's no help. There is only
an example for getting the selected node.
But I need help SETTING the selected node. Code like
string val = "OU=Testunit,DC=Domain,DC=local";

this.tV.SelectedNode = val;
can't work, because val is a string not a node and I've got the info of the
node to select only in a string.

What must I change? Or do you know an other example?

Thanks for your reply!!
 
K

Kevin Yu [MSFT]

Hi Martin,

The TreeView doesn't support searching through its nodes. In this case you
have to write a search method, which go through all the nodes in the whole
tree and looks for the matched string. Then pass the TreeNode reference to
the SelectedNode property. HTH.

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
K

Kevin Yu [MSFT]

You're welcome!

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top