473,657 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ 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(rootNo de);
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 1407
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(rootNo de);
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
1883
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 importantly, in Windows Explorer, you can drag the treeview's right edge to resize it to your will. How can I do this with my treeview (at runtime obviously)? Do I need to use a splitter? Any info would be appreciated very much.
4
1452
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> <answer OID="001">Some Text</answer> <answer OID="002">Some Text</answer> <answer OID="003">Some Text</answer>
2
1103
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? Thanks
6
7475
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 code to VB .NET. Set objNode = TreeView1.Nodes.Add() changes to objNode = TreeView1.Nodes.Add() but iam getting an error that add has wrong number of arguments and if i add
0
986
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 root node, then a single node below that. I don't want to show either of these, I only want the nodes below to be shown. Can I do this?
5
5807
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, the options they are allowed to see are all different and specified in a MSACCESS table. Can I populate a Treeview directly from my MSAccess table ? I can then of course filter the table to only show that users options.
3
1628
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 because my tree is ENORMOUS. It can possibly hold millions of nodes. The problem is keeping this treeview constrained as a user clicks through the nodes. I've tried putting it in a DIV with a set width and height, but the problem is that when you...
3
5012
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
1614
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 TreeView control and have the following questions. + I'm not sure if it's possible to include a checkbox control as part of a TreeView. Do I need to use images of a checkbox in my ImageIndex property? I'd imaging I'd need 4 images of directories...
3
1718
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 way when you select a node in order to change its associated data, you have easy access to its Set function. The way I normally handel this situation is is to create an enum of all the different types that the treeview contains. I then have a
0
8402
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8829
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8508
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8608
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5633
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2733
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 we have to send another system
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.