数据库对象的Treeview C# [英] Treeview for database objects C#
问题描述
大家好,
如何用来自gridview或dt的数据填充树形视图,
数据表有4列:
1-家长ID
2-家长姓名
3-子女ID
4-孩子的名字
我的尝试:
我发现几乎所有静态树的例子都是硬编码的,所以这在我的场景中不会被充分使用
Hello everyone,
How to fill Tree view with data from gridview or dt,
Data table has 4 columns:
1- Parent ID
2- Parent Name
3- Child ID
4- Child Name
What I have tried:
Almost all of the examples that i found where static trees, hard coded so this won't be use full in my scenario
推荐答案
这是快速回答论坛的相当高的订单。
如果你付了足够的钱,我很乐意为你编写代码。 :)
我假设您将数据库中的数据导入一个或多个数据表。
首先,您可以看看这些文章:
从C#中的数据表创建Treeview | C#中的动态Treeview控件C#中的Treeview节点|如何在C#中将节点绑定到运行时的Treeview控件作者代码| AuthorCode [ ^ ]
[更新]
似乎是上述链接部分代码中的错误。
您将收到编译器错误并非所有代码路径都返回值。
请参阅下面的修复。
This is a pretty tall order for the Quick Answer forum.
If you paid enough I would happily write the code for you. :)
I assume you get the data from the database into one or more data tables.
As a start you can look at these articles:
Create Treeview From Datatable In C#| Dynamic Treeview Control In C# | Treeview Nodes In C# |How To Bind Nodes To Treeview Control At Runtime In C# | Author Code | AuthorCode[^]
[UPDATE]
Seems to be a bug in part of the code from the link above.
You will get the compiler error "Not all code paths return a value."
See the fix below.
private TreeNode Searchnode(string nodetext, TreeView trv)
{
foreach (TreeNode node in trv.Nodes)
{
if (node.Text == nodetext)
{
return node;
}
}
// Added the line below, so the method returns null if no node was found
return null;
}
那么你必须要注意方法可以返回null的情况。
< br $> b $ b
填充TreeView控件C# [ ^ ]
至于阻力&请看这里:在C#中拖动树节点 [ ^ ]
这些文章应该让你入门。
Then you have to take care of the case that the method can return null.
Populate a TreeView Control C#[^]
As for drag & drop, look here: Dragging tree nodes in C#[^]
These articles should get you started.
这篇关于数据库对象的Treeview C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!