473,396 Members | 1,921 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,396 software developers and data experts.

Treeview problem

He. I'm trying to create a treeview that will show data from access database
in hierarchical way. Database structure is: ID, FirstName, LastName,
IDBoss - IDBoss is referenced to ID. Treeview should look like this:

-employee1

---employee2

---employee3

------employee4

---employee5

---employee6

------employee7

---------employee8

------employee9

Can someone please send here some code (please in vb.net 2005) that will do
that work, or give me a hint. So far I create function that populate
treeview but only 3 levels.

Here is my code:

(Sorry on my english)

----
Private Sub FillTree()

Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data
Source=|DataDirectory|\baza.mdb")

Dim rootAdapter As New OleDb.OleDbDataAdapter("SELECT * FROM zaposlenici
WHERE ID = 1", conn)

Dim childAdapter As New OleDb.OleDbDataAdapter("SELECT * FROM zaposlenici
WHERE ID <1", conn)

Dim treeDataSet As New DataSet()

treeDataSet.EnforceConstraints = False

rootAdapter.Fill(treeDataSet, "Parents")

childAdapter.Fill(treeDataSet, "Children")

treeDataSet.Relations.Add("relacija",
treeDataSet.Tables("Parents").Columns("ID"), _

treeDataSet.Tables("Children").Columns("IDBoss"))

treeDataSet.Relations.Add("relacija2", _

treeDataSet.Tables("Children").Columns("ID"), _

treeDataSet.Tables("Children").Columns("IDBoss"))

TreeView1.Nodes.Clear()

Dim parent As DataRow

For Each parent In treeDataSet.Tables("Parents").Rows

Dim parentNode As New TreeNode(parent("LastName").ToString() & " " &
parent("FirstName").ToString())

Dim child As DataRow

For Each child In parent.GetChildRows("relacija")

Dim folderNode As New TreeNode(child("LastName").ToString() & " " &
child("FirstName").ToString())

Dim item As DataRow

For Each item In child.GetChildRows("relacija2")

folderNode.Nodes.Add(New TreeNode(item("LastName").ToString() & " " &
item("FirstName").ToString()))

Next item

parentNode.Nodes.Add(folderNode)

Next child

TreeView1.Nodes.Add(parentNode)

Next parent

TreeView1.ExpandAll()

End Sub
Jul 12 '06 #1
2 1144
I would solve this by:

Filling a dataset with all employees.
Using RECURSION I would add an employee, and then iterate through the
dataset to find any one below him.

Rinse, lather, and repeat.

Jul 13 '06 #2

"Steven Nagy" <le*********@hotmail.comwrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
>I would solve this by:

Filling a dataset with all employees.
Using RECURSION I would add an employee, and then iterate through the
dataset to find any one below him.

Rinse, lather, and repeat.
can you write some example code, please.
Jul 13 '06 #3

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

Similar topics

4
by: Ian Powell | last post by:
Hi I've got objects in an sorted ArrayList like: P:\ P:\\DOCS P:\\i386 P:\\i386\ASMS P:\\i386\ASMS\1000 P:\\i386\ASMS\1000\MSFT
0
by: Björn Bengtsson | last post by:
Hello! I have an urgent problem concerning ASP.NET, ADO.NET, SQL Server, XML and the TreeView control. I have two tables; one describing the products and one describing their relationships. A...
4
by: Karim El Jed | last post by:
Hi, I'm trying to expand a special Node of my TreeView from Codebehind. I have a TreeView on a page for navigating to another site. On the other tsite here is the same TreeView more precisely a...
14
by: Evan Kontos | last post by:
I am trying to implement a Treeview w/an XML file and I even copied and pasted examples from MSDN but can't get them to work. Any suggestions welcome. XML File <TREENODES> <TREENODE...
4
by: Jeff Beem | last post by:
I have a class that inherits from TreeView. The treeview has tooltips for the nodes but they're showing up behind the form. Has anyone seen this? Are there any known fixes? Thanks in advance,...
3
by: christof | last post by:
I've got a really easy problem, please help me: There are two pages in one I'm creating a TreeView like that: TreeView dbTree = new TreeView(); TreeNode dbTreeRoot = new TreeNode("Root");...
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...
8
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the...
1
by: Nikron | last post by:
Hi, I'm having an issue with the ASP.NET 2.0 Treeview control and persisting its' state accross requests. My Control is embedded within a master page and is used for site navigation. My problem...
0
by: bsturg21 | last post by:
Hello, I have an app that has a custom treeview which inherits the base treeview class and I am having a problem with the way the treeview is being redrawn. Each node in the treeview represents 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...

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.