Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2006

Tip: Looking for answers? Try searching our database.

Treeview problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MaPet - 13 Jul 2006 12:33 GMT
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.OLEDB.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
Robbe Morris [C# MVP] - 16 Jul 2006 02:08 GMT
Take this code from 2003.  It is the same stuff.

http://www.eggheadcafe.com/articles/treeview_databinding.asp

Signature

Robbe Morris - 2004-2006 Microsoft MVP C#
Earn money answering .NET questions
http://www.eggheadcafe.com/forums/merit.asp

> I'm trying to create a treeview that will show data from access database
> in hierarchical way. Database structure is: ID, FirstName, LastName,
[quoted text clipped - 88 lines]
>
> End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.