selectednodechanged event on .NET 2.0 treeview problem

T

tanya foster

Hello,
I have populated a treeview in asp.net 2.0 from an xmldocument. The
treeview structure in the asp web page looks something like...

-orderdata
-order
-lines
-operations
-materials
-material
-partnumber="123"
-description="brass bolt"
-quantity="1"
-type="Job"
-units="grams"
-material
-partnumber="ABC"
-description="plywood"
-quantity="9"
-type="Job"
-units="pounds"
-material
-partnumber="999"
-description="metal frame"
-quantity="2"
-type="Job"
-units="whole"

....



the point is, there are multiple material children to a materials parent.

The treeview is name TreeViewForXml

My selectednodechanged callback begins like..

Protected Sub TreeViewForXml_SelectedNodeChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TreeViewForXml.SelectedNodeChanged

Dim TextToEdit, StringToParse() As String

HideAllEditFields()

ListBoxForOrderInformation.Items.Add("Selected value=" &
TreeViewForXml.SelectedNode.Value & _
" text=" & TreeViewForXml.SelectedNode.Text)
......

The problem is, sometimes if I click on quantity="2" (or any other quantity
that is not in the first material child of materials), the selectednode(or
the message I get in my listbox) is quantity="1"(or always the quantity node
in the first material child of materials). In the above example, there are
3 material children of materials but there could be 20 material children or
more.

I am seeing this happen if I selected partnumber="999", the TreeviewForXml.
SelectedNode is partnumber="123"(the first child in the list of material
children).

What am I doing wrong to trap selectednode?

I know the TreeNodeCollection.IndexOf(treenode) method will return the first
occurrence of a node if it appears multiple times in the collection.

Is this also the rule with a treeview and selectednode?

thanks.
 
T

tanya foster

Good news. Problem solved. =


Some background:

A treenode has two fields that may be set to strings: text and value.

When I was creating my treeview, I was setting the treenode.text field and the treeno=
de.value field to the same string, in this example, =E2=80=9Cmaterial=E2=80=9D.

=


I changed the code used to populate the treeview by using a running counter for each ma=
terial treenode created.

For example,

The first material treenode contained =

treenode.value =3D material1 =

treenode.text =3D material

The second material treenode contained =

treenode.value =3D material2 =

treenode.text =3D material

The 3rd material treenode contained =

treenode.value =3D material3 =

treenode.text =3D material

The nth material treenode contained =

treenode.value =3D materialn =

treenode.text =3D material

=


After I did this, when I selected a partnumber, type, units, etc(children of each mat=
erial node), it did resolved correctly to the treenode I thought I selected.

So this tells me that asp.net 2.0 treeview needs some uniqueness to the VALUE field of=
treenodes for selectedNode to correctly resolve.

=


I also tested not setting the value field to a unique string and setting the text field=
to a unique string and the problem still existed.

=


I just wish this caveat was documented.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top