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

Home Posts Topics Members FAQ

Populating four levels of tree view from the database

34 New Member
Hi all,
I am trying to populate tree view from the database. Till two levels i can populate it fine but when it reaches third level it doesn't expand. Below is the code, it has been taken from the reference of micrososft

Sub PopulateNode(By Val sender As Object, ByVal e As TreeNodeEventAr gs)

' Call the appropriate method to populate a node at a particular level.
If e.Node.ChildNod es.Count = 0 Then

Select Case e.Node.Depth

Case 0
' Populate the first-level nodes.
PopulateCategor ies(e.Node)

Case 1
' Populate the second-level nodes.
PopulateProduct s(e.Node)

Case 2
' Populate the third-level nodes.
PopulateResourc es(e.Node)

Case Else
'do mothing

End Select
Else
e.Node.Parent.T ext = "xx"
End If

End Sub

Sub PopulateCategor ies(ByVal node As TreeNode)

' Query for the product categories. These are the values
' for the second-level nodes.
Dim ResultSet As DataSet = RunQuery("SELEC T Block4.BlockCod e, sessiontype.typ e, sessiontype.Blo ckID,sessiontyp e.SessionID FROM Block4 INNER JOIN sessiontype ON Block4.BlockID = sessiontype.Blo ckID Where Block4.BlockCod e='xx'")

' Create the second-level nodes.
If ResultSet.Table s.Count > 0 Then

' Iterate through and create a new node for each row in the query results.
' Notice that the query results are stored in the table of the DataSet.
Dim row As DataRow

For Each row In ResultSet.Table s(0).Rows

' Create the new node. Notice that the CategoryId is stored in the Value property
' of the node. This will make querying for items in a specific category easier when
' the third-level nodes are created.
Dim newNode As TreeNode = New TreeNode()
'newNode.Text = "Seminars"
newNode.Text = row("type").ToS tring()
newNode.Value = row("SessionID" ).ToString()

' Set the PopulateOnDeman d property to true so that the child nodes can be
' dynamically populated.
newNode.Populat eOnDemand = True

' Set additional properties for the node.
newNode.SelectA ction = TreeNodeSelectA ction.Expand

' Add the new node to the ChildNodes collection of the parent node.
node.ChildNodes .Add(newNode)

Next

End If

End Sub
Sub PopulateProduct s(ByVal node As TreeNode)

' Query for the product categories. These are the values
' for the second-level nodes.
Dim ResultSet As DataSet = RunQuery("SELEC T semsymp4.stitle ,semsymp4.ID,se ssiontype.type FROM semsymp4 INNER JOIN sessiontype ON semsymp4.Sessio nID = sessiontype.Ses sionID where semsymp4.Sessio nID=" & node.Value)

' Create the second-level nodes.
If ResultSet.Table s.Count > 0 Then

' Iterate through and create a new node for each row in the query results.
' Notice that the query results are stored in the table of the DataSet.
Dim row As DataRow

For Each row In ResultSet.Table s(0).Rows

' Create the new node. Notice that the CategoryId is stored in the Value property
' of the node. This will make querying for items in a specific category easier when
' the third-level nodes are created.
Dim newNode As TreeNode = New TreeNode()
'newNode.Text = "Seminars"
newNode.Text = row("stitle").T oString()
newNode.Value = row("ID").ToStr ing()

' Set the PopulateOnDeman d property to true so that the child nodes can be
' dynamically populated.
newNode.Populat eOnDemand = True

' Set additional properties for the node.
newNode.SelectA ction = TreeNodeSelectA ction.Expand


' Add the new node to the ChildNodes collection of the parent node.
node.ChildNodes .Add(newNode)


Next

End If

End Sub


Sub PopulateResourc es(ByVal node As TreeNode)

' Query for the products of the current category. These are the values
' for the third-level nodes.

Dim ResultSet As DataSet = RunQuery("SELEC T Resources.Resou rceID, Resources.Resou rceTitle,Resour ces.ResourceURL ,Resources.ID, semsymp4.ID AS Expr1, semsymp4.stitle FROM Resources INNER JOIN semsymp4 ON Resources.ID = semsymp4.ID where Resources.ID=" & node.Value)

' Create the third-level nodes.
If ResultSet.Table s.Count > 0 Then

' Iterate through and create a new node for each row in the query results.
' Notice that the query results are stored in the table of the DataSet.
Dim row As DataRow

For Each row In ResultSet.Table s(0).Rows

' Create the new node.
Dim NewNode As TreeNode = New TreeNode(row("R esourceTitle"). ToString())
'NewNode.Naviga teUrl = row("ResourceUR L").ToString

' Set the PopulateOnDeman d property to false, because these are leaf nodes and
' do not need to be populated.
NewNode.Populat eOnDemand = False

' Set additional properties for the node.
'NewNode.Select Action = TreeNodeSelectA ction.None
'
' Add the new node to the ChildNodes collection of the parent node.

node.ChildNodes .Add(NewNode)

Next

End If

End Sub

Function RunQuery(ByVal QueryString As String) As DataSet

' Declare the connection string. This example uses Microsoft SQL Server
' and connects to the Northwind sample database.
Dim ConnectionStrin g As String = "xxx"

Dim DBConnection As SqlConnection = New SqlConnection(C onnectionString )
Dim DBAdapter As SqlDataAdapter
Dim ResultsDataSet As DataSet = New DataSet
Response.Write( QueryString)
' Try

' Run the query and create a DataSet.
DBAdapter = New SqlDataAdapter( QueryString, DBConnection)
DBAdapter.Fill( ResultsDataSet)

' Close the database connection.
DBConnection.Cl ose()

'Catch ex As Exception

' Close the database connection if it is still open.
If DBConnection.St ate = ConnectionState .Open Then

DBConnection.Cl ose()

End If

'Message.Text = "Unable to connect to the database."

' End Try

Return ResultsDataSet

End Function


I don't understand what the problem is ,
Please, if you could help me. It's urgent.
Jun 14 '07 #1
0 1725

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

Similar topics

3
14029
by: Steve Johnson | last post by:
Been banging my head on this for two days now. Hope someone can help! My test program below is in the form of a single JSP, with a Node class build in. (All the coded needed to run is below.) The technical requirements: 1) Store tree data in the database so that it can be extracted as a tree structure. For test purposes,
5
3378
by: Travis Pupkin | last post by:
Hey, I've done a number of product catalogs/galleries with one or two category levels (Category > Subcategory). The straightforward way to do this, of course, is to use database fields for Category and Subcategory and query off of those fields. I have a client now who is interested in what sounds to me to be an unnecessarily complex catalog with an as of yet undefined number of category levels at their disposal.
3
10813
by: imani_technology_spam | last post by:
We need to present hierarchical data on a web page, the same way the tree view shows files in Windows Explorer. Here's the catch: that tree view needs to be bound to a SQL Server database. How can this be done?
0
1248
by: serge calderara | last post by:
Dear all, I have an VB windows application that colect information form a remote database and then populate the tree view with part of the reords. As database data can be huge , I have used the Queeue threading process to colect those information. Then when the callback function is called I populate my treeview with teh return object. As the treeview control is not on the same thread, I have to use the Invoke method.
0
2173
by: Tree menu using XML | last post by:
I have one XML file that has nodes and sub node and each and every node has the attribute call visible if its value is true then diplay this node else don't display thid node, but this condition i am able to check using xpath in asp.net 2.0 till MenuItem node. if i check visible attribute value till SubMenuLevel0 node then in tree it will not display the MenuItem Node at all Note: My tree Menu will start from MenuItem node and it will...
5
2365
by: Shane | last post by:
I wonder if someone has any ideas about the following. I am currently producing some reports for a manufacturing company who work with metal. A finished part can contain multiple sub-parts to make up the finished part. The sub-parts can also be made up of sub-parts and those sub-parts can also be made up of sub-parts etc etc. All parts are contained within the same table and I have a seperate table
2
2388
by: James L | last post by:
I have finally developed some code that allows you to re populate a tree view and re select the last node that was clicked. However, you have to hard code it for the number of levels the tree view could possibly be expanded to. Any ideas? //The test program has a button to set the path and a button to execute the path finding code. //This is so that you can close the treeview back up to the root to ensure the correct code is selected
3
8374
by: babu17 | last post by:
hi , I have a database table with 3 columns table1: eid ename parentid 0 root 0 1 child1 0 2 child2 0
7
1986
by: sosamv | last post by:
Hi all!, I'm creating a app with PHP and MySQL, the system administrator is capable of creating profiles, on each profile we create, we add a custom access menu (a javascript tree view menu), theres a <textarea> where the admin enters the tree array, example: , ], , , ] I want to create a "preview" button that would open a popup with the preview of the tree.... the script of the pop-up to create the tree preview is:
0
8163
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8667
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
8324
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
7145
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...
1
6104
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
5561
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
4156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1471
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.