动态地将TreeNode转换为DataTable
有很多方法可以将数据表转换为树视图(树节点),例如这个。但是有什么方法可以创建一个维护层次结构的数据表。对于前。如果 TreeNode
就像
A-A1
-A2-A21
-A22
B-B1
-B2-B21
-B3-B31
-B32-B321
-B322
-B33
-B4
数据表中的以下内容一样。然后我可以将其保存在数据库中或在datagrid
中向用户显示。
所有列都可以采用 string
值。
有什么方法可以将 treenode
传递给函数 &它将动态创建这样的数据表。 treenode
结构每次都会改变,这就是为什么我不能对其进行硬编码。假设我有一个像这样的递归函数。
public void CreateData(TreeNode trn)
{
foreach(TreeNode t in trn.Nodes)
{
CreateData(t);
}
}
我在理解递归函数的代码流程方面面临困难。 任何建议表示赞赏。
谢谢。
There are plenty of methods to convert datatable into treeview (treenode) like this. But is there any way to do create a datatable maintaining hierarchy. For ex. if TreeNode
is like
A-A1
-A2-A21
-A22
B-B1
-B2-B21
-B3-B31
-B32-B321
-B322
-B33
-B4
should look like following in datatable. Then i can either save it in the databse or show it to the user in a datagrid
.
All column can have take string
values.
Is there any way so i can pass a treenode
to a function & it will create datatble like this dynamically. treenode
structure will change everytime that's why i can not hardcode it. Suppose i have a recursive function like this.
public void CreateData(TreeNode trn)
{
foreach(TreeNode t in trn.Nodes)
{
CreateData(t);
}
}
i am facing difficulty in understanding flow of code for recursive function.
any suggestion is appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个伪代码,希望它能帮助您解决问题
Here's a pseudo code, hope it will help you to deal with your problem
如果您无法理解该函数或它的工作原理,您可能需要阅读
深度优先搜索
。这正是您正在做的+您应该添加代码来保存您当前所在的节点。If you cann't understand that function or how it should work, you might want to read about
Depth-first search
. Its exacly what you're doing + you should add code that save the node you're in at moment.