473,395 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 3783
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.GetDirectoryName for
each nodes FileLocation.

last="D:\"

while(reader.Read())
{
current=Path.GetDirectoryName(reader.FileLocation) .
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*******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.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.GetDirectoryName for
each nodes FileLocation.

last="D:\"

while(reader.Read())
{
current=Path.GetDirectoryName(reader.FileLocation) .
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*******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.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
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
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 ....
4
by: Mike | last post by:
how can i populate a treeview from a database? websites with examples would help.
3
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...
9
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...
6
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...
0
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. ...
0
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...

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.