惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Jina AI
Jina AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog
T
The Blog of Author Tim Ferriss
量子位
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
小众软件
小众软件
Recent Announcements
Recent Announcements
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
I
InfoQ
美团技术团队
G
Google Developers Blog
Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
云风的 BLOG
云风的 BLOG
博客园 - 【当耐特】
IT之家
IT之家
Microsoft Security Blog
Microsoft Security Blog
博客园 - 聂微东
Last Week in AI
Last Week in AI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Help Net Security

博客园 - somesongs

好多年没回到这个园子 有趣的多媒体 发布简短计划,备忘 Intelligencia.UrlRewriter, 解决404找不到文件的问题 forms验证如此简单 在一个页面中调用另一个页面定义的函数 .net中,数据提交完毕后,刷新绑定控件,清空输入框的好办法,就是在时间函数的最后加入Response.Redirect(Request.FilePath); [转] Trace跟踪输出进行调试 Flash的全屏播放(转) flash中实现拖拽 .net从后台返回js的提示框 编写xmlhelper类【翻译】 [转]C#网络编程概述 【转】C#网络编程初探 只需一行代码实现增删查改,微软已经让我们很简单。谈AccessDataSource的使用。 document.body.clientHeight与document.documentElement.clientHeight 动态将Js代码写入到Head标签中 Asp.net中删除前的提示信息 location和history的详细设置
Treeview中,递归生成从当前选中节点到根节点的全路径
somesongs · 2009-02-02 · via 博客园 - somesongs

Treeview常用来导航,有时候需要有一个横向的路径式的导航,我们可以直接从treeview动态生成。这个内容让我对递归有了一些亲近的味道,以前总是怕怕。

 1         protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
 2         {
 3 
 4             TreeNode theNode = TreeView1.SelectedNode;
 5 
 6             Label1.Text = getTextPath(theNode);
 7         }
 8 
 9         //生成从当前节点到根节点的路径
10         public string getTextPath(TreeNode theNode)
11         {
12             string result = theNode.Text;
13 
14             if (theNode.Parent != null)
15             {
16                 result = theNode.Parent.Text + " >> " + result;
17 
18                 getTextPath(theNode.Parent);
19             }
20 
21             return result;
22         }

一个多简单的递归!结果如下图: