what is equivalent of vb.net treenode.nextnode property in asp.net webcontrols.treenode

what is equivalent of vb.net treenode.nextnode property in asp.net webcontrols.treenode

Post by tanya fost » Thu, 18 May 2006 04:28:22


Hello,
I am re-writing a visual basic .net application(visual studio 2003) in an
asp.net application(visual studio 2005). The vb.net application relied on a
treeview and hence, treenodes. The treeview and treenode class in asp.net
is limited compared to vb.net's. In vb.net, the treenode had a nextnode
property which was equivalent to finding the next sibling of the treenode.
asp.net's treenode has a child property and a parent property. Any ideas on
how to determine the sibling of a treenode in asp.net's treenode class? I
am looking for the nextnode of the treeview.selectednode.
thanks.
 
 
 

what is equivalent of vb.net treenode.nextnode property in asp.net webcontrols.treenode

Post by Alvin Brun » Thu, 18 May 2006 21:45:22

There is no next pointer, you will need to find the current node and then
iterate its collection of child nodes. The effect is the same, different
perspective.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.yqcomputer.com/
-------------------------------------------------------

 
 
 

what is equivalent of vb.net treenode.nextnode property in asp.net webcontrols.treenode

Post by tanya fost » Fri, 19 May 2006 21:58:18

Alvin,
Sounds good but I am not visualizing it completely. Getting the
currentnode is easy as in treeview.selectednode. If I iterate through the
children of treeview.selectednode, then I am not getting a sibling of the
current node but i would be going after its children. There is a "child"
and a "parent" property available. I want the sibling or nextnode treenode.


Do you mean to get the parent of the currentnode and then iterate through
its children? I am sorry I don't quite understand but would love to.
 
 
 

what is equivalent of vb.net treenode.nextnode property in asp.net webcontrols.treenode

Post by tanya fost » Sat, 20 May 2006 02:58:27

Thanks Alvin for your help.

Here is my code which might help another asp.net developer or anyone else
when they are trying to get to the sibling treenodes or nextnodes in system.
web.ui.webcontrols.treeview or treenode classes.

Here is an example of the treeview structure used(I am displaying it as xml
though)

....
<material>
<partnumber>12345</partnumber>
<description>5 feet long pipe</description>
<units>10</units>
<type>stocked</type>
</material>
<material>
<partnumber>8888</partnumber>
<description>machine saw and drill</description>
<units>2</units>
<type>on order</type>
</material>
...


When the user selects the partnumber to edit, after I validate that the new
partnumber exists in a table, I want to update the description treenode with
the matching description from the same table. I do not allow the user to
edit the description treenode.

The function below(written in .NET Framework version 2.0 asp.net) receives a
string and updates the description treenode of the partnumber the user
selected to edit.

TreeViewForXml is a system.web.ui.webcontrols.treeview

Assumption #1: TreeViewForXml.SelectedNode was a partnumber changed to a
valid new partnumber

Assumption #2: When the treeview was populated, the treenode.value field
was populated with the name of the xml element or xml attribute

Private Function UpdateDescriptionTreeNode(ByVal NewDescription As String)
As Boolean

Dim NodeOfInterest As TreeNode
Dim k As Integer
Dim FoundDescriptionTreeNode As Boolean

FoundDescriptionTreeNode = False
'get the parent node of the selected node
NodeOfInterest = TreeViewForXml.SelectedNode.Parent

'now parse through the children nodes to locate selectednode's sibling
that contains description

If Not (NodeOfInterest Is Nothing) And NodeOfInterest.ChildNodes.Count >
0 Then

For k = 0 To NodeOfInterest.ChildNodes.Count - 1
If NodeOfInterest.ChildNodes(k).Value = "description" Then
NodeOfInterest.ChildNodes(k).Text = NewDescription
FoundDescriptionTreeNode = True
End If
Next

End If

Return FoundDescriptionTreeNode

End Function

I do hope the asp.net team SOON implements the nextnode property just like
in the System.Windows.Forms.treenode class.

Thanks for your suggestions and clarifications Alvin.