TreeView 中的 TreeNode 与 Visual C 中的属性++ - 如何实现?

发布于 2024-11-27 05:16:31 字数 573 浏览 2 评论 0原文

我在 Visual C++ 解决方案中使用 TreeView 来表示和更改 XML 内容。我在这个项目中使用 Visual Studio 2010 (.NET/Windows Forms)。我的一些 TreeNode 必须具有属性。不幸的是,Visual Studio 中的 TreeNode 似乎没有属性。

我现在想通过向应该具有属性的 TreeNode 添加不可见的子节点并将属性值保存在这些不可见的子节点中来解决此问题。同样,Visual Studio 中的 TreeNode 不提供任何使它们不可见的属性。我现在的想法是简单地派生一个自定义 TreeNode 类并添加一个布尔属性是否应该隐藏 TreeNode。如果该属性为 true,我“只需”必须覆盖 TreeView 的方法,该方法在添加时绘制 TreeNode(或进入 View 或其他内容)。不幸的是,这就是我被困住的地方。我必须重写哪个函数才能完成此任务?

顺便说一句:我必须添加可见性属性吗?实际上,只需将节点转换为 Custom-TreeNode(与 TreeNode 完全相同)就足够了,然后仅在它是 TreeNode 类型时绘制它,并在它是 CustomTreeNode 时隐藏它。正确的?

感谢您的帮助!

I am using a TreeView's in my Visual C++ Solution to represent and alter XML-Content. I use Visual Studio 2010 for this project (.NET/Windows Forms). Some of my TreeNodes have to have Attributes. Unfortunately, TreeNodes in Visual Studio do not seem to have Attributes.

I now wanted to solve this by adding invisible Child-Nodes to TreeNodes which are supposed to have Attributes and saving the Attribute-Value in those invisible Child-Nodes. Again, TreeNodes in Visual Studio do not offer any Property for making them invisible. My Idea now was to simply derive a Custom TreeNode-Class and add a boolean Property whether the TreeNode should be hidden or not. If the property is true I "just" have to overwrite the method of the TreeView which draws the TreeNode when being added (or comes into View or whatever). Unfortunately, that's where I am stuck. Which Function do I have to override to get this done?

BTW: Do I have to add a visibility property? Actually it should suffice to just cast the Node to the Custom-TreeNode (which is the exact same as TreeNode) and then only draw it when it is of Type TreeNode and hide when it is CustomTreeNode. Right?

Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文