Expanding a tree view with a path

G

Guest

I have a tree view with a root, 3 noodes(1,2,3) each having one sub node.

I drill down to a node.

I get the path by saying treeView1.selectedNode.fullpath and assign it to a
variable.

If I redraw the tree, or close it up and want to expand the same node again,
can i do this via the path?

Thank you kindly.
 
N

Nicholas Paldino [.NET/C# MVP]

James,

This seems a little more complicated than it should have to be.

Basically, what you have to do is parse apart the full path, delimited
by the value in the PathSeparator property. Then, you would take Nodes
property on the TreeView, and look for the first key (through the IndexOfKey
method). Then, you take that node, and look for the next key in the
collection of TreeNode instances returned from Node.

Once you have the final node, you can call the EnsureVisible method on
the last node, and then it will expose the node in the tree.

Hope this helps.
 
G

Guest

I cannot seem to see an index of key mathod or an ensure visible method.


I have this so far.

string path = treeView1.SelectedNode.FullPath;
string delimit = @"\";
char [] delimiter = delimit.ToCharArray();
string [] split = null;

split = path.Split( delimiter );

int treeNodeIndex;
TreeNode t = new TreeNode( split[0].ToString());
treeNodeIndex= treeView1.Nodes[0].Nodes.IndexOf( t );

thanks
Nicholas Paldino said:
James,

This seems a little more complicated than it should have to be.

Basically, what you have to do is parse apart the full path, delimited
by the value in the PathSeparator property. Then, you would take Nodes
property on the TreeView, and look for the first key (through the IndexOfKey
method). Then, you take that node, and look for the next key in the
collection of TreeNode instances returned from Node.

Once you have the final node, you can call the EnsureVisible method on
the last node, and then it will expose the node in the tree.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

James L said:
I have a tree view with a root, 3 noodes(1,2,3) each having one sub node.

I drill down to a node.

I get the path by saying treeView1.selectedNode.fullpath and assign it to
a
variable.

If I redraw the tree, or close it up and want to expand the same node
again,
can i do this via the path?

Thank you kindly.
 
N

Nicholas Paldino [.NET/C# MVP]

James,

You have to call the IndexOfKey method, passing the current element in
split that you are looking at.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

James L said:
I cannot seem to see an index of key mathod or an ensure visible method.


I have this so far.

string path = treeView1.SelectedNode.FullPath;
string delimit = @"\";
char [] delimiter = delimit.ToCharArray();
string [] split = null;

split = path.Split( delimiter );

int treeNodeIndex;
TreeNode t = new TreeNode( split[0].ToString());
treeNodeIndex= treeView1.Nodes[0].Nodes.IndexOf( t );

thanks
Nicholas Paldino said:
James,

This seems a little more complicated than it should have to be.

Basically, what you have to do is parse apart the full path,
delimited
by the value in the PathSeparator property. Then, you would take Nodes
property on the TreeView, and look for the first key (through the
IndexOfKey
method). Then, you take that node, and look for the next key in the
collection of TreeNode instances returned from Node.

Once you have the final node, you can call the EnsureVisible method
on
the last node, and then it will expose the node in the tree.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

James L said:
I have a tree view with a root, 3 noodes(1,2,3) each having one sub
node.

I drill down to a node.

I get the path by saying treeView1.selectedNode.fullpath and assign it
to
a
variable.

If I redraw the tree, or close it up and want to expand the same node
again,
can i do this via the path?

Thank you kindly.
 
G

Guest

As i said earlier, i cannot see these methods you are refering to anywhere.
Is this a .net2 feature?

Nicholas Paldino said:
James,

You have to call the IndexOfKey method, passing the current element in
split that you are looking at.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

James L said:
I cannot seem to see an index of key mathod or an ensure visible method.


I have this so far.

string path = treeView1.SelectedNode.FullPath;
string delimit = @"\";
char [] delimiter = delimit.ToCharArray();
string [] split = null;

split = path.Split( delimiter );

int treeNodeIndex;
TreeNode t = new TreeNode( split[0].ToString());
treeNodeIndex= treeView1.Nodes[0].Nodes.IndexOf( t );

thanks
Nicholas Paldino said:
James,

This seems a little more complicated than it should have to be.

Basically, what you have to do is parse apart the full path,
delimited
by the value in the PathSeparator property. Then, you would take Nodes
property on the TreeView, and look for the first key (through the
IndexOfKey
method). Then, you take that node, and look for the next key in the
collection of TreeNode instances returned from Node.

Once you have the final node, you can call the EnsureVisible method
on
the last node, and then it will expose the node in the tree.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have a tree view with a root, 3 noodes(1,2,3) each having one sub
node.

I drill down to a node.

I get the path by saying treeView1.selectedNode.fullpath and assign it
to
a
variable.

If I redraw the tree, or close it up and want to expand the same node
again,
can i do this via the path?

Thank you kindly.
 

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