数据集和层次数据如何排序
这可能是一个愚蠢的问题,但目前我在这个问题上碰壁了。
我有一些本质上是分层的数据,位于 ADO.NEt 数据集中。第一个字段是 ID,第二个字段是名称,第三个字段是父 ID。
ID 姓名 家长 ID
1 空气处理 NULL
2 压缩机 1
3 电机 4
4 压缩机 1
5 电机 2
6 控制器 4
7 控制器 2
因此树如下所示:
1- 空气处理
4- 压缩机
6 - 控制器
3 - 电机
2- 压缩机
7-控制器
5 - Motor
我想要弄清楚的是如何以与在树视图中查看的顺序相同的顺序获取数据集,在本例中是节点适当级别的级别,然后是节点的子级的级别。按名称排序的适当级别。
这就像将其绑定到树视图,然后简单地沿着节点向下工作以获得正确的顺序。
任何链接或方向将不胜感激。
This is probably a dumb question, but I've hit a wall with this one at this current time.
I have some data which is hierarchial in nature which is in an ADO.NEt dataset. The first field is the ID, the second is the Name, the third is the Parent ID.
ID NAME Parent ID
1 Air Handling NULL
2 Compressor 1
3 Motor 4
4 Compressor 1
5 Motor 2
6 Controller 4
7 Controller 2
So the tree would look like the following:
1- Air Handling
4- Compressor
6 - Controller
3 - Motor
2- Compressor
7- Controller
5 - Motor
What I'm trying to figure our is how to get the dataset in the same order that ths would be viewed in a treeview, which in this case is the levels at the appropriate levels for the nodes and then the children at the appropriate levels sorted by the name.
It would be like binding this to a treeview and then simply working your way down the nodes to get the right order.
Any links or direction would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会重新组织数据以使其更加规范化,但是如果您必须使用现有的数据,请执行嵌套的 for 语句(其中第一个语句在 ParentID 字段中查找 null。如果您不知道有多少层深)数据显示,这会让你的工作变得更加困难,但这是可以完成的。
I would re-organize the data to be more normalized, however if you must work with what you have, do nested for statements (where the first one looks for the null in the parentID field. If you don't know how many layers deep the data goes, it will make your job more difficult, but it can be done.