Solved

Populate Treeview dynamically from SQL 2000 stored procedure in VB.net 2.0

Posted on 2009-05-18
3
1,055 Views
Last Modified: 2012-05-07
Hi
How do I dynamically pouplate a treeview in VB.net 2.0 (visual studio 2005) from a sql 2000 stored procedure?
Number of child nodes changes.The database structUre is as below

ContenId ParentContentID Name
1             0                          Main
2             1                          Home
3              1                          News
This is to populate a treeview to get all the pages/menu in CMS and for users to allow add/edit pages and add new pages under existing pages as displayed in the Treeview.
Working on a deadline - so any help is appreciated.
Awaiting responsE
Thanks a Ton.
0
Comment
Question by:NewUser09
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
Brian Crowe earned 150 total points
ID: 24416914
I have attached some code that I used to do something very similar.  Basically you establish a root node then you just recursively add children referencing the ParentID.

Hope this helps

BriCrowe
	Private Sub FillTaskTree()
 
		Dim tn As TreeNode
		Dim i As Integer
		Dim dv As New DataView(dsUserAdmin.Tables("Task"))
 
		tvTasks.Nodes.Clear()
 
		dv.RowFilter = "ParentTaskID IS NULL"
		dv.Sort = "DisplayOrder"
		For i = 0 To dv.Count - 1
			tn = tvTasks.Nodes.Add(dv(i)("Name").ToString)
			tn.Tag = dv(i)("TaskID")
			tn.ImageIndex = TaskIcon.ClosedContainer
			tn.SelectedImageIndex = TaskIcon.ClosedContainer
			FillTaskChildNodes(tn)
			tn.Expand()
		Next
	End Sub
 
	Private Sub FillTaskChildNodes(ByVal tnParent As TreeNode)
 
		Dim tnChild As TreeNode
		Dim i As Integer
		Dim dv As New DataView(dsUserAdmin.Tables("Task"))
 
		Dim strfilter As String = "ParentTaskID = " + tnParent.Tag.ToString + _
		 " AND TaskTypeID <> " + CInt(TaskType.Action).ToString
		dv.RowFilter = strfilter
		dv.Sort = "DisplayOrder"
		For i = 0 To dv.Count - 1
			tnChild = tnParent.Nodes.Add(dv(i)("Name").ToString)
			tnChild.Tag = dv(i)("TaskID")
			Select Case CInt(dv(i)("TaskTypeID"))
				Case TaskType.Container
					tnChild.ImageIndex = TaskIcon.ClosedContainer
					tnChild.SelectedImageIndex = TaskIcon.ClosedContainer
				Case TaskType.Tool
					tnChild.ImageIndex = TaskIcon.Tool
					tnChild.SelectedImageIndex = TaskIcon.Tool
				Case TaskType.Report
					tnChild.ImageIndex = TaskIcon.Report
					tnChild.SelectedImageIndex = TaskIcon.Report
			End Select
			FillActionNodes(tnChild)
			FillTaskChildNodes(tnChild)
		Next
	End Sub

Open in new window

0
 

Author Comment

by:NewUser09
ID: 24417276
Hi

Thank u very much for u'r comment.
I guess u are using .net 3 framework -Iam using .net framework 2.0 and I have found  a way to do it using the below link.
http://aspalliance.com/732 

Thanks
0
 
LVL 34

Expert Comment

by:Brian Crowe
ID: 24423107
Actually the code is fairly old and was written in VS2003 so I expect I was using .Net 1.1 but as long as you found something that works for you.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question