Treeview节点在单击文本时不扩展 [英] Treeview node not expanding on clicking on text
问题描述
我有一个树视图,其中有两个父节点0的子节点和一个没有ID的主节点。
根节点
0 - >儿童1
1 - > SubChilds
3 ---> SubChild1
1 - >子孙女
0 - >儿童2
2 - > SubChilds
2 - > SubChilds
树结构如上。问题是每当我点击Child 2时,Child 1节点都会被扩展,我已经检查过使用断点并发现每当我点击Child 2时,sleectednode.text会显示Child 1.如何清除它?
下面给出了一段代码:
------------- -----------------------------------
Treeview1_SelectedNodeChanged()
{
Datatable dt = // Treeview绑定
ds.tables。 add (dt);
TreeNode selectedNode = New TreeNode();
selectedNode = this .Treeview1.SelectedNode.Text;
}
------------------------------ ------------------
这里selectedNode总是显示第一个Child节点的文本,即使我点击第二个子节点。我使用数据表绑定SQL表中的树。
感谢&问候,
SaJ
这是因为您的treenodes有重复值,更改行
parentTreeNode.Value = firstDataRows [ParentId]。ToString();
到
parentTreeNode.Value = firstDataRows [Id]。ToString();
这样他们就会有独特的价值
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
这篇关于Treeview节点在单击文本时不扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!