如何在Treeview中使用SelectedNodeChanged事件获取子节点的数据? [英] How to get data of child node using SelectedNodeChanged event in Treeview ?

查看:580
本文介绍了如何在Treeview中使用SelectedNodeChanged事件获取子节点的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TreeView控件,并且想要类似
的数据
类别
>子类别
>部门

在上面,我只有类别和子类别,但我没有获得部门的价值

请尽快给我答复.

I am using TreeView Control and I want Data like

Category
> Sub Category
> Division

in above I got only Category and Sub Category but i didn''t get value of Division

Please send me answer ASAP.

推荐答案

Mukesh,

我想按节点的值是指Tag属性.因此,正如Sanjay在NodeMouseClick事件中告诉我们的那样,我们可以使该语句单击Node
TreeNode tn = e.Node;

现在获取所有的子节点,并有各自的value(Tag).我们可以遍历节点并获得相应的值.
这是示例代码

Hi Mukesh,

By Values of Nodes i suppose you are refering to the Tag property. So as Sanjay told in the NodeMouseClick event we can get the Node clicked by this statement
TreeNode tn = e.Node;

Now to get all the child nodes and there respective value(Tag). We can loop through the nodes and get there respective values.
Here''s the sample code

TreeNode tn = e.Node;
           string st = null;

           foreach (TreeNode t1 in tn.Nodes)
           {
               st += "Node Name:" + t1.Text + " Node Data: " + t1.Tag.ToString()+ "\n";


           }
           MessageBox.Show(st);




希望这对您有所帮助.如有任何疑问,请告诉我.




Hope this helps you. Incase of any confusion do let me know.


您好,Mukesh可以给我发送yuu为此所做的确切代码.
Hi Mukesh can you send me the exact code yuu are doing for this. May be i can help you then.


在"NodeMouseClick"事件上,有一个TreeNodeMouseClickEventArgs对象e.

用于获取触发了事件的Node对象
"e.Node"
On "NodeMouseClick" event there is a TreeNodeMouseClickEventArgs object e.

for getting the Node object on which the event has fired use
"e.Node"


这篇关于如何在Treeview中使用SelectedNodeChanged事件获取子节点的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆