更新时间:2023-11-25 23:27:16
这是因为您的treenodes有重复值,更改行parentTreeNode.Value = firstDataRows [ParentId]。ToString();
到parentTreeNode.Value = firstDataRows [Id]。ToString();
这样他们就会有独特的价值lockquote>Hi,
I have a tree view in which there are two child nodes with parentID 0 and a main node with no ID.
Root Node
0--> Child 1
1--> SubChilds
3--->SubChild1
1--> Subchilds
0--> Child 2
2--> SubChilds
2--> SubChilds
The tree structure is as above. The problem is that whenever I click on Child 2 the Child 1 node gets expanded, I have checked using breakpoints and found out that whenever I click on Child 2 the sleectednode.text shows Child 1. How can I clear this?
A piece of the code is given below :
------------------------------------------------Treeview1_SelectedNodeChanged() { Datatable dt = //Treeview binding ds.tables.add(dt); TreeNode selectedNode = New TreeNode(); selectedNode = this.Treeview1.SelectedNode.Text; }
------------------------------------------------
Here selectedNode always shows the text of the first Child node even if I click on the second Child Node. I am binding the tree from the SQL table using a datatable.
Thank & Regards,
SaJThis happens because your treenodes have duplicate values, change the lineparentTreeNode.Value = firstDataRows["ParentId"].ToString();
toparentTreeNode.Value = firstDataRows["Id"].ToString();
So that they will have unique values