469,609 Members | 2,088 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

TreeView Nodes Appearing in Wrong Spot

LacrosseB0ss
113 100+
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.

Expand|Select|Wrap|Line Numbers
  1. Dim grandparent As String = ""
  2.         Dim alpha As String = ""
  3.         Dim parent As String = "'"
  4.         Dim child As String = ""
  5.         Dim counter As Integer = 0
  6.         Dim cNode As TreeNode = Nothing
  7.         Dim ccNode As TreeNode = Nothing
  8.         Dim cccNode As TreeNode = Nothing
  9.  
  10.         tree.DataSource = Nothing
  11.         tree.DataBind()
  12.  
  13.         Try
  14.             tree.Nodes.Clear()
  15.             With objDataReader
  16.                 While .Read
  17.                     Dim current As String = .Item("Group").ToString & ""
  18.                     'add grandparent (1st) node
  19.                     'this will be the Group (chosen from ddlGroup)
  20.                     If grandparent <> current Then
  21.                         grandparent = current
  22.                         parent = ""    ' reset the parent string
  23.                         cNode = New TreeNode(grandparent.ToString)
  24.                         'tvw_View.Nodes.Add(cNode)
  25.                         tree.Nodes.Add(cNode)
  26.                     End If
  27.  
  28.                     current = .Item("ItemAndCourse").ToString & ""
  29.                     alpha = Left(current, 1)
  30.  
  31.                     'add Course name under Alphabetic headings
  32.                     'if next item is different letter, add it
  33.                     If UCase(parent) <> UCase(alpha) Then
  34.                         If cNode Is Nothing Then
  35.                             cNode = New TreeNode(grandparent.ToString)
  36.                             tree.Nodes.Add(cNode)
  37.                         End If
  38.  
  39.                         parent = alpha
  40.                         ccNode = New TreeNode(parent.ToString)
  41.                         cNode.ChildNodes.Add(ccNode)
  42.                     End If
  43.  
  44.                     'add Course name under appropriate letter heading
  45.                     If child <> current Then
  46.                         If cNode Is Nothing Then
  47.                             cNode = New TreeNode(child.ToString)
  48.                             tree.Nodes.Add(cNode)
  49.                         End If
  50.                         child = current
  51.                         cccNode = New TreeNode(child.ToString)
  52.                         ccNode.ChildNodes.Add(cccNode)
  53.                     End If
  54.  
  55.                     'add number to counter - show # of entries found
  56.                     counter += 1
  57.                 End While
  58.             End With
  59.  
Nov 1 '06 #1
0 1026

Post your reply

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

Similar topics

3 posts views Thread by Soul | last post: by
4 posts views Thread by Jeroen Ceuppens | last post: by
4 posts views Thread by Ian Powell | last post: by
6 posts views Thread by Jan Krouwer | last post: by
14 posts views Thread by Mr.D | last post: by
6 posts views Thread by amruta | last post: by
1 post views Thread by kvicky | last post: by
6 posts views Thread by xla76 | last post: by
reply views Thread by Solution2021 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.