Hey all!
I have just started using the TreeView object in asp. There are some other applications I have seen use it and I have copied some of the code from them at work. What happens is on a form, an item is selected from a dropdown box and based on what the user selects, there are items linked to that group in a different field. I would like these items to show up as tree view nodes split aplhabetically.
This works fine. The grandparent node (selected by user) appears on top. Then the first letter of the following items are parents slightly indented. However, here is where the problem occurs. Children under these Alpha headings appear under the correct headings but indented so they are directly under the root node. I would like them indented again under the alpha headings.
Any help that can be offered is greatly appreciated. I have included some of my code below.
I have just started using the TreeView object in asp. There are some other applications I have seen use it and I have copied some of the code from them at work. What happens is on a form, an item is selected from a dropdown box and based on what the user selects, there are items linked to that group in a different field. I would like these items to show up as tree view nodes split aplhabetically.
This works fine. The grandparent node (selected by user) appears on top. Then the first letter of the following items are parents slightly indented. However, here is where the problem occurs. Children under these Alpha headings appear under the correct headings but indented so they are directly under the root node. I would like them indented again under the alpha headings.
Any help that can be offered is greatly appreciated. I have included some of my code below.
Code:
Dim grandparent As String = "" Dim alpha As String = "" Dim parent As String = "'" Dim child As String = "" Dim counter As Integer = 0 Dim cNode As TreeNode = Nothing Dim ccNode As TreeNode = Nothing Dim cccNode As TreeNode = Nothing tree.DataSource = Nothing tree.DataBind() Try tree.Nodes.Clear() With objDataReader While .Read Dim current As String = .Item("Group").ToString & "" 'add grandparent (1st) node 'this will be the Group (chosen from ddlGroup) If grandparent <> current Then grandparent = current parent = "" ' reset the parent string cNode = New TreeNode(grandparent.ToString) 'tvw_View.Nodes.Add(cNode) tree.Nodes.Add(cNode) End If current = .Item("ItemAndCourse").ToString & "" alpha = Left(current, 1) 'add Course name under Alphabetic headings 'if next item is different letter, add it If UCase(parent) <> UCase(alpha) Then If cNode Is Nothing Then cNode = New TreeNode(grandparent.ToString) tree.Nodes.Add(cNode) End If parent = alpha ccNode = New TreeNode(parent.ToString) cNode.ChildNodes.Add(ccNode) End If 'add Course name under appropriate letter heading If child <> current Then If cNode Is Nothing Then cNode = New TreeNode(child.ToString) tree.Nodes.Add(cNode) End If child = current cccNode = New TreeNode(child.ToString) ccNode.ChildNodes.Add(cccNode) End If 'add number to counter - show # of entries found counter += 1 End While End With