473,796 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populate treeview from database

Hello all,

First off all, I appollogize for my englisch.
I have a problem.
I have a table in my sql database with 2 fields.
Field 1 is an ID, and Field 2 contains the complete file locations.

What I would like to do is create a treeview from this table.
For example:
Table:
Id FileLocation
1 D:\Demo\001\01\ 00001.tiff
2 D:\Demo\001\01\ 00002.tiff
3 D:\Demo\002\01\ 00001.tiff
4 D:\Demo\002\01\ 00002.tiff
5 D:\Demo\002\01\ 1\00001.tiff
6 D:\Demo\002\02\ 00001.tiff
7 D:\Demo\002\02\ 00002.tiff
8 D:\Demo\003\01\ 00001.tiff
9 D:\Demo\003\01\ 00002.tiff

The treeview would look something like this:
- D:\
- Demo
- 001
- 01
- 0001.tiff
- 0002.tiff
- 002
- 01
- 0001.tiff
- 0002.tiff
- 1
- 0003.tiff
- 002
- 02
- 0001.tiff
- 0002.tiff
- 003
- 01
- 0001.tiff
- 0002.tiff

As you can see I don't know how deep the tree can be.
What I do know is that they all have the same root level : D:\Demo\

I hope someone can help me with this problem.
I would appreciate any help.

Thank you,
Nathan

Aug 29 '06 #1
2 3834
Hi -

One of three options:

1. If using SQL then write a stored procedure to generate an extra column
being the level of each node. Still need to process the information in order
to update the tree. Doesn't make it that much easier in the client
application as even if nodes are on the same level then they may have
different parentage.

2. Retrieve the data and write logic in the application to process the
records calculating the level of each node using Path.GetDirecto ryName for
each nodes FileLocation.

last="D:\"

while(reader.Re ad())
{
current=Path.Ge tDirectoryName( reader.FileLoca tion).
If current=last then
// node is on the same level. add node to end of current nodes
parent.
If current.length> last.length and last.substring( current.length) =current
then
// node is below the current level. create nodes as appropriate and
add the new node.
Else
// node has different parentage. Need to work out from current
location what nodes need to be added (probably easiest to work from the
root).
End if

last = current
}

As you can see the code above in 2 is iterative and providing you keep track
of the last nodes position you should easily be able to update the tree.

3. Alternatively you could add each node walking the nodes in the tree from
the root adding (or re-using) nodes as appropriate.

HTH

- Andy

<th*******@gmai l.comwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
Hello all,

First off all, I appollogize for my englisch.
I have a problem.
I have a table in my sql database with 2 fields.
Field 1 is an ID, and Field 2 contains the complete file locations.

What I would like to do is create a treeview from this table.
For example:
Table:
Id FileLocation
1 D:\Demo\001\01\ 00001.tiff
2 D:\Demo\001\01\ 00002.tiff
3 D:\Demo\002\01\ 00001.tiff
4 D:\Demo\002\01\ 00002.tiff
5 D:\Demo\002\01\ 1\00001.tiff
6 D:\Demo\002\02\ 00001.tiff
7 D:\Demo\002\02\ 00002.tiff
8 D:\Demo\003\01\ 00001.tiff
9 D:\Demo\003\01\ 00002.tiff

The treeview would look something like this:
- D:\
- Demo
- 001
- 01
- 0001.tiff
- 0002.tiff
- 002
- 01
- 0001.tiff
- 0002.tiff
- 1
- 0003.tiff
- 002
- 02
- 0001.tiff
- 0002.tiff
- 003
- 01
- 0001.tiff
- 0002.tiff

As you can see I don't know how deep the tree can be.
What I do know is that they all have the same root level : D:\Demo\

I hope someone can help me with this problem.
I would appreciate any help.

Thank you,
Nathan

Aug 29 '06 #2
Hi Andy,

Thank you for your answer.
I think that your option 2 can work for me.
I tried to figure it out how to populate and where to create new
childnodes,
but i can't seem to get it to work.

Would you be so kind to give me an working sample code ?

Thank you.
Nathan
Andy Bates schreef:
Hi -

One of three options:

1. If using SQL then write a stored procedure to generate an extra column
being the level of each node. Still need to process the information in order
to update the tree. Doesn't make it that much easier in the client
application as even if nodes are on the same level then they may have
different parentage.

2. Retrieve the data and write logic in the application to process the
records calculating the level of each node using Path.GetDirecto ryName for
each nodes FileLocation.

last="D:\"

while(reader.Re ad())
{
current=Path.Ge tDirectoryName( reader.FileLoca tion).
If current=last then
// node is on the same level. add node to end of current nodes
parent.
If current.length> last.length and last.substring( current.length) =current
then
// node is below the current level. create nodes as appropriate and
add the new node.
Else
// node has different parentage. Need to work out from current
location what nodes need to be added (probably easiest to work from the
root).
End if

last = current
}

As you can see the code above in 2 is iterative and providing you keep track
of the last nodes position you should easily be able to update the tree.

3. Alternatively you could add each node walking the nodes in the tree from
the root adding (or re-using) nodes as appropriate.

HTH

- Andy

<th*******@gmai l.comwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
Hello all,

First off all, I appollogize for my englisch.
I have a problem.
I have a table in my sql database with 2 fields.
Field 1 is an ID, and Field 2 contains the complete file locations.

What I would like to do is create a treeview from this table.
For example:
Table:
Id FileLocation
1 D:\Demo\001\01\ 00001.tiff
2 D:\Demo\001\01\ 00002.tiff
3 D:\Demo\002\01\ 00001.tiff
4 D:\Demo\002\01\ 00002.tiff
5 D:\Demo\002\01\ 1\00001.tiff
6 D:\Demo\002\02\ 00001.tiff
7 D:\Demo\002\02\ 00002.tiff
8 D:\Demo\003\01\ 00001.tiff
9 D:\Demo\003\01\ 00002.tiff

The treeview would look something like this:
- D:\
- Demo
- 001
- 01
- 0001.tiff
- 0002.tiff
- 002
- 01
- 0001.tiff
- 0002.tiff
- 1
- 0003.tiff
- 002
- 02
- 0001.tiff
- 0002.tiff
- 003
- 01
- 0001.tiff
- 0002.tiff

As you can see I don't know how deep the tree can be.
What I do know is that they all have the same root level : D:\Demo\

I hope someone can help me with this problem.
I would appreciate any help.

Thank you,
Nathan
Sep 1 '06 #3

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

Similar topics

1
8792
by: Jacob John | last post by:
how to populate a treeview in c#.net (windows forms) from a SQL Server database ??? pls help me. thanks in advance, JJK
0
1544
by: T.H.M | last post by:
This is the all code. Very simple and short. I need to populate a treeView in aspx page (web form) from XML file. I get en completion error:No overload for method 'TreeNode' takes '1' arguments . using System; using System.Web.UI.WebControls; using Microsoft.Web.UI.WebControls; using System.Xml;
4
8617
by: Mike | last post by:
how can i populate a treeview from a database? websites with examples would help.
3
10153
by: Jan Wrage | last post by:
Hi! I would like to implement a treeview in my existing application. It should show my entire Active-Directory structure, i.e. all Groups, Containers and OUs. Could somebody help me with that. Im trying for about 3 hours but can't get it to work. Thank you!
9
2102
by: Marina | last post by:
Hello! I have a database with some customers. Each one of them has 3 other customers under him etc. (something like an MLM system). Now, I want to create a treeview with this. Eg. C1 C11 C111 C1111 C1112 C1113
6
9975
by: Beginner | last post by:
Hi, I'm trying to populate a TreeView from an existing and filled in ListView (lvwBuild). lvwBuild is a basic two column listview which can have any number of rows. I would like the first column of lvwBuild to be a node and the second column to be a branch on the TreeView (hopefully I have the syntax correct). I've been researching how to do this but have come up empty. I'm guessing that you would fill an array from lvwBuild and...
0
1593
by: Patrick | last post by:
Hi, Im trying to populate my treeview control onmy webpage with the information that is stored in a xml file, but i cant seem to find any good references about it. The xml file looks like this. <root> <page id="1" name="test1" src="test.htm" /> <page id="2" name="test2" src="test2.htm"> <page id="4" name="test2.1" src="test3.htm"> <page id="9" name="test2.1.1" src="test5.htm" />
0
2072
by: xmail123 | last post by:
How to populate a treeview from a dataset I am very new to C#. I need to create a Windows form that will read a SQL table and populate a treeview. I can connect to the DB, create the dataadapter, populate a data set. The problem is how to use the dataset to populate a treeview. I have looked at a few examples here but none use a dataset, or the data structure was different and I could not modify to work with my data or the examples...
1
1828
nurikoAnna
by: nurikoAnna | last post by:
Goodday... Please help me to populate data in a list view...call data from the database.. Currenty i am using MySQL as a database.... Ex. I have a database name dbSection..Then I have a table t_section and another table is t_student...What I like to do using a treeview....I want to display in the treevee the parent node as Section Name then the child nodes are list of the student names...
0
9680
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
10456
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
10230
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
10174
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
10012
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
7548
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
5442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4118
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

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.