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

Home Posts Topics Members FAQ

Nested hierarchial data in treeview

petepell
3 New Member
Hello all,

I am developing an application in VB 2008 that works with a SQL2005 DB to store and manipulate employee data. In one section of the app I want to be able to show a treeview of the hierarchy as a whole showing a nested hierarchy of who reports to who such that when it is first loaded, all you will see is the top guy in the company with a plus next to his name. Opening that will reveal his first level reports and opening those will reveal the next level and so on. This one piece of the puzzle has been the elemental drive of this application and it has yet to be accomplished.

The fields in the database that I need to work on are as such:

1. AssociateNumber (Basically the employee number of the person. Formatted like A-232)

2. Sponsor (This is the field showing the AssociateNumber of the person this associate reports to. It is also formatted like A-232)

Thus if A-20 reported to A-2 then it would look like this in A-20's row

AssociateNumber =A-20, Sponsor=A-2

I understand that I need to query the database and build a recordset for the data that I want to display and then populate the treeview from that recordset but I have been horribly unsuccessful thusfar.

Mostly I seem to be able to get the recordset created (using the Northwind as a test DB pulling from EmployeeID and ReportsTo fields) but when I create the treeview it seems to put all 9 of the employees on the first level as well as nesting them causing duplication of names.

Below is the code I used to accomplish this disaster.

Any help would be greatly appreciated!

Thanks!
Peter

_______________ _______________ _______________ _

Public Function BuildHierarchy( ) As DataSet

'Experimental code for the nested hierarchial view

Dim result As New DataSet
Dim connString As String = "server = .\sqlexpress;in tegrated security = true;database = Northwind"
Dim myConnection = New SqlConnection(c onnString)

If (True) Then
Dim query As String = "Select EmployeeID,Firs tName,LastName, Title,ReportsTo from Employees"

Dim myCommand As New SqlCommand(quer y, myConnection)
Dim myAdapter As New SqlDataAdapter

myCommand.Comma ndType = CommandType.Tex t
myAdapter.Selec tCommand = myCommand
myAdapter.Fill( result)
myAdapter.Dispo se()

End If

result.DataSetN ame = "Employees"
result.Tables(0 ).TableName = "Employee" '

Dim relation As New DataRelation("P arentChild", result.Tables(" Employee").Colu mns("EmployeeID "), result.Tables(" Employee").Colu mns("ReportsTo" ), True)

relation.Nested = True
result.Relation s.Add(relation)
result.GetXml()

Dim nodeAssociate As TreeNode
Dim nodeSubAssociat e As TreeNode

For Each rowAssociate In result.Tables(" Employee").Rows
nodeAssociate = New TreeNode()
nodeAssociate.T ext = rowAssociate("E mployeeID") & ". " & rowAssociate("F irstName") & " " & rowAssociate("L astName")
tvwHierarchy.No des.Add(nodeAss ociate)

For Each rowTitle In rowAssociate.Ge tChildRows("Par entChild")
nodeSubAssociat e = New TreeNode()
nodeSubAssociat e.Text = rowTitle("Emplo yeeID") & ". " & rowTitle("First Name") & " " & rowTitle("LastN ame")
nodeAssociate.N odes.Add(nodeSu bAssociate)
Next
Next

End Function
Feb 8 '08 #1
0 1185

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1176
by: rawCoder | last post by:
Hi All, Is the Hierarchial Display of data not in DataGridView in Visual Studio 2005 Beta 2 even? I am talking about showing rows with tree like (+) and (-) and collapse and expand in a DataGrid like hierarchial FlexGrid. Is there any FREE control out there preferrably with source code to do so? And is there any plan to roll out a grid with this feature.
2
1990
by: Franz | last post by:
I want to show the content of the xml with a control which allows to show the nodes in a nested way. I don't want to use DataGrid which shows the nodes in a tabular form. Is there any suitable control for me? Thanks. -- My C++ and C# ( Traditional Chinese ) Web Site : www.franzwong.com/Home.php
1
3077
by: Hazz | last post by:
I have 5 tables in SQL Server. Each with the following design and a sample chain of the relationships from the root (WRL - World) UUS is the 'Code' of the first table and it is the 'Parent' value of the second table, etc. Parent varchar 3 Name varchar 60 Code varchar 3 WRL United States UUS <- UUS California UCA <- UCA North Coast UNC <- UNC
2
1980
by: Rythm Music | last post by:
I am trying to get some help on creating a Multilevel Hierarchial Datagrid. What I mean is that the Hierarchial level is unknown. There could be many related records or none. Also there could be multiple categories. Hopefully the data below will give some idea. Here is some data: Category Amount 1 10 1.1 5
6
6967
by: Susan H | last post by:
I have Visual Studio 2005, trying to properly bind to a nested object tree. I can bind to the top level object just fine, but can't seem to "hook" my nested object in. I have a ShoppingCart object, which has 1+ Shipment objects, which each have 1+ LineItem objects. Pretty standard. I'm looking to print a report that prints out the header for the shopping cart, and then sections for each shipment, and so on. I am floundering on how...
0
1643
by: Henry | last post by:
I am trying to create a TreeView control that works with an ADO Dataset DataTable or the new BindingSource stuff in .NET 2.0 to build a Treeview that is populated. This is what I came up with so far... I can't run it yet because I don't have the DataTable source... I still want to get some sort of assessment as to whether I am heading in the right direction. Here is the code: ================================ using System;
5
2284
by: Jake K | last post by:
What purpose does nesting a class inside another class typically server? Are there conditions where this would be beneficial? Thanks a lot.
0
955
by: Benny J | last post by:
Hello, I'm trying to implement 'Excel-like' hierarchial Editable GridView using nested Grids. When hierarchy is opened e.g. a row and it's child row I would like to align columns and edit fields in same position without depending if row is parent or child row. Has anyone experience how colums and editable fields could be in same
3
4703
by: dutsnekcirf | last post by:
I have a treeview control on a custom task pane in Excel. I've enable the ability to use Drag & Drop (by following this how-to) on the treeview to change the order of the nodes. The problem though is if I close the application and then go back in, the nodes are back in the order they were before I had reordered them. Is there a way that I can modify my DragDrop event to permanently change the index of the nodes? Here's my code if you're...
0
9621
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
10267
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...
1
10040
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
9914
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...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6717
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();...
0
5355
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
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2852
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.