473,473 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

TreeView Nodes Appearing in Wrong Spot

LacrosseB0ss
113 New Member
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 1113

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

Similar topics

3
by: Soul | last post by:
Hi, I am learning C# at the moment. I am trying to develop a simple program that will get data from a MS Access database into a dataSet. The result of dataSet should be something like: Year ...
4
by: Jeroen Ceuppens | last post by:
Hi, I want to make something that adds a TreeNode to the end of TreeView, that TreeView Looks like + Level 1 + Level 2 + Level 3 - Level last
4
by: Ian Powell | last post by:
Hi I've got objects in an sorted ArrayList like: P:\ P:\\DOCS P:\\i386 P:\\i386\ASMS P:\\i386\ASMS\1000 P:\\i386\ASMS\1000\MSFT
6
by: Jan Krouwer | last post by:
I have a treeview which is populated from a relational database. In order to copy part of the tree, I need to add to the database the relationship of the part of the tree to be copied but with new...
14
by: Mr.D | last post by:
How do I save/load the contents of a Treeview to a file? I have found several good examples written i VB6, but not a single one for VB.NET. Please help. ---- Tim
6
by: amruta | last post by:
Dim objNode As MSComctlLib.Node TreeView1.ImageList = ImageList1 'Assign the image list to TreeView Set objNode = TreeView1.Nodes.Add() 'Create the Server Node I need to conver the above VB 6.0...
1
by: kvicky | last post by:
I am trying to load child nodes to a TreeNode in a TreeView in a ASP.net web application. The Treeview with parent nodes are loaded on a Page_load while doing if( ! ISPostback ) and then in the...
1
by: Woof | last post by:
Hi, I'm populating the nodes of a Tree View control via an SQL database, with the lowest child nodes (leaves from now on) Text field being set to a lengthy set of HTML. The outcome is a...
6
by: xla76 | last post by:
I have a simple treeview (treeview1) to which I have added two nodes (nodeA and nodeB) which have n levels of child nodes. What I want is to be able to identify whether the child node I select...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
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...
0
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,...
0
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...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.