如何在树视图 Access/VBA 中上下移动根节点
好的。我在树视图上做了很多工作,我认为允许用户根据他们认为合适的方式上下移动树视图的节点会很方便。我的结构只是一个简单的两级树视图,但是每个根节点都必须有一个子节点。例如:
Root
child
child
child
Root
child
child
Root
child
child
child
child
我编写了代码,您一次只能从根节点中勾选一个框。我想要做的是单击一个按钮,然后让选中的根节点向上(或向下)移动一个位置(当然也带着它的子节点)。
我能想象这项工作的唯一方法是完全重建节点,比以前高一级。当节点开始有更多子节点等时,这似乎太耗时了。
当我搜索时,我发现了大量 C# 结果,但由于我使用的是 VBA,所以它对我没有任何帮助。如果有人在重建整个节点之外有任何建议,我很乐意听到。谢谢
Ok. I've been working a lot on a treeview and I decided that it would be convenient to allow the users to move the nodes of the treeview up and down however they see fit. My structure is just a simple two level treeview, however every root node must have a child. For example:
Root
child
child
child
Root
child
child
Root
child
child
child
child
I have code written where you can only check off one box from the Root nodes at a time. What I want to do is click a button, and have the checked root node move up (or down) one position (of course taking its children with it).
The only way I can imagine this working would be to completely rebuild the node one level higher than it was previously. This seems like it would be far too time consuming when the nodes begin to have more children etc.
When I searched I found a ton of C# results, but since I'm using VBA it didn't help me at all. If anybody has any suggestions outside of rebuilding the entire node I would love to hear it. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决这个问题的方法是将节点的键和文本保存在临时变量中,清除键,然后切换它们。
此时,我循环遍历所有子节点并将它们添加到节点数组中。我将每个节点的 Nodes.Parent 属性设置为相反的节点,然后一切就基本完成了。
这是可能的,因为表中的数据取决于用户如何构建树视图,因此一旦他们让树视图显示他们想要的方式,我就可以保存我需要的信息并在他们打开该特定记录备份时重建它。我希望这一点很清楚,但我下面有一些代码块可以帮助解决这个问题。
^上面的代码用于将 n 向上移动到 n.Previous 位置
下面的代码是切换节点的子节点(如果有的话),
我希望这个示例能够帮助任何具有类似两级树结构并希望做这样的事情的人。我是通过单击按钮来完成此操作的,但是可以将其重新设计为拖放方法。
The way I solved this was by saving the keys and text of my nodes in temporary variables, clearing the keys, and then switching them.
At this point, I then loop through all of the children and add them into an array of Nodes. I set the nodes.Parent property of each of them to the opposing node, and then it was all pretty much done.
This is possible because the data in the table depends on how the user structures the treeview, so once they have the treeview displaying how they want it, I can save the information I need and rebuild it when they open that particular record back up. I hope this is clear but I have some code chunks below to help clear this up.
^The code above is made to move n up into n.Previous spot
The following code, is to switch the children of the nodes (if any)
I hope this example will help anybody else who has a similar two level tree structure and is looking to do something like this. I am doing it on a button click, however it could be reworked for a drag and drop method.