473,471 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Treeview questions...

Hi Everybody

I have a string that contains part of a directory structure that will be
created in the future. I want to display this future tree on a treeview for
the user see and then approve it.

I was able to populate the first level of the tree, but I'll need some
information to how populate the child levels of the tree.

For example, if I have the directory (not created on the OS yet):

Dir1
Dir1/Dir2
Dir1/Dir2/Dir3

Now I'm using:

iniSlash = path.IndexOf(@"\");
if(iniSlash != -1)
{
return path.Substring(0, iniSlash);
}

So I get the first directory (Dir1) and I add it to the tree:

TreeNode ChildNode = new TreeNode(rootNode);
aNode.Nodes.Add(ChildNode);

Where the rootNode = path (returned from the string).

How can I select the populated nodes and get the child for each node on the
tree?

Someone has something like this ?

Thanks!

Eduardo

--
Eduardo de Morais Ferrari
Oct 20 '05 #1
1 1380
Ferrari, Eduardo wrote:
Hi Everybody

I have a string that contains part of a directory structure that will
be created in the future. I want to display this future tree on a
treeview for the user see and then approve it.

I was able to populate the first level of the tree, but I'll need
some information to how populate the child levels of the tree.

For example, if I have the directory (not created on the OS yet):

Dir1
Dir1/Dir2
Dir1/Dir2/Dir3

Now I'm using:

iniSlash = path.IndexOf(@"\");
if(iniSlash != -1)
{
return path.Substring(0, iniSlash);
}

So I get the first directory (Dir1) and I add it to the tree:

TreeNode ChildNode = new TreeNode(rootNode);
aNode.Nodes.Add(ChildNode);

Where the rootNode = path (returned from the string).

How can I select the populated nodes and get the child for each node
on the tree?

Someone has something like this ?


Use recursion.
First split the path on '\'. This will give you all folders in an
array:
string[] folders = path.Split('\');

then create a hashtable which stores path to treenode combinations.
So if you have the path c:\foo\bar\bar2, it will result in 3 nodes:
c:\foo, bar and bar2 and you store these 3 nodes as:
c:\foo
c:\foo\bar
c:\foo\bar\bar2

in the hashtable, with the full path to their folder as key and the
treenode as value

then create a small routine which in a loop from front to back renders
a path in the treeview. That routine first splits the folders as above,
then walks from front to back through the array and builds a relative
path from the parent path. So in our example:
c:\foo doesn't have a parent path, as it's the first element in the
array. bar is a folder which has c:\foo as parent path. Grab the node
from the hashtable and add a subnode to that node with the text 'bar',
and store the node under c:\foo\bar in the hashtable.

etc.

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Oct 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: fgh | last post by:
Hello, two questions please: 1) In a treeview, I want to display folders like it is done in Windows Explorer. Do I have to do this manually or can I set something up in VS.NET 2003? 2) Most...
4
by: IndeX? | last post by:
Hello, I'm parsing from an xml file (using DOM), so that i can place certain nodes in a TreeView. Xml file looks like this: <questions> <question ID="Question 01" Text="Some Text"> <answers>...
2
by: EdB | last post by:
I'll admit, it was late....but I could not find the answer to these two questions. How can determine if the node that a user clicked on: 1) is a parent (top level only)? 2) has children? ...
6
by: amruta | last post by:
Dim objNode As MSComctlLib.Node TreeView1.ImageList = ImageList1 'Assign the image list to TreeView Set objNode = TreeView1.Nodes.Add() 'Create the Server Node I need to conver the above VB 6.0...
0
by: Alan Silver | last post by:
Hello, I have a treeview control that is populated from an XML file. I have two questions... 1) Is it possible to specify where the treeview starts showing nodes? I aks this as there is a...
5
by: Paul | last post by:
Hi, I am a self taught VBA programmer, and I'm trying to learn VB2005 Express (The price was right). I like the look of the treeview control, and I'd like to use it as a menu system for my users,...
3
by: William Sullivan | last post by:
I desperately want to replace my hand-made ajax treeview with the 2.0 TreeView. The webpage I'm designing uses the postbacks to dynamically fill the treeview. The reason why I'm doing this is...
3
by: orit | last post by:
I have the following xml: <?xml version="1.0" ?> <course> <globalProperties> <externalMetadata> <source>ADL</source> <model>ADL SCORM 1.0</model> </externalMetadata> </globalProperties>
2
by: engwar1 | last post by:
I'm a .Net newbie and have started writing a Windows Forms application to assist me in choosing files/directories to move from one drive to another. Basically what I want is something like the...
3
by: bg_ie | last post by:
Hi, Lets say I have a TreeView with nodes that represent objects of a number of different types. Is there a way of associating the Set method of each object with its node in the TreeView? That...
0
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,...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.