473,586 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
+ 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 1122

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

Similar topics

3
3231
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 Semester Code Task --------------------------------------------------- "2003" "One" "CSE9020" "Deliverable Item 1" "2003" "One" "CSE9020"...
4
5252
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
7586
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
1513
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 ids. I have built a collection of the right number of ids. I am using the following code to recursively go through the tree (some code left out)....
14
15070
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
7467
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 code to VB .NET. Set objNode = TreeView1.Nodes.Add() changes to objNode = TreeView1.Nodes.Add() but iam getting an error that add has wrong...
1
693
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 Treeview event I am dynamically trying to load the child nodes to the exisisting TreeView. The problem is since the TreeView is being loaded on not...
1
2254
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 beautifully formated list of data, where the leaves each show several rows from the SQL database. THE PROBLEM: When I expand each node level manually...
6
11949
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 is under NodeA or NodeB. I can do this by splitting the selectednode.fullpath of the child node but there must be a better way. Can any kind soul...
0
7839
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...
0
8200
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. ...
0
8215
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
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...
0
5390
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...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1179
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...

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.