且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Treeview节点在单击文本时不扩展

更新时间: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,
SaJ

This happens because your treenodes have duplicate values, change the line

parentTreeNode.Value = firstDataRows["ParentId"].ToString();



to

parentTreeNode.Value = firstDataRows["Id"].ToString();



So that they will have unique values