检查Treeview XML子节点,然后检查父节点是否合法 [英] Treeview XML child node checked then parent node checked authomatic

查看:88
本文介绍了检查Treeview XML子节点,然后检查父节点是否合法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编码休闲游戏时遇到问题:
如果有人在treeview控件中检查了一个子节点,我希望对该子节点的父节点进行检查.

像这样的东西:

I am having problems coding the fallowing :
If somebody checks a child node in the treeview control, I want the parent node of the that child node to be checked.

Some thing like:

For each node as treenode in nodes
    If childrennode.checked = true then
        Parentnode.check = true
    End if
Next




以下代码将XML信息加载到我的treeview控件中.树视图中的每个节点都有一个复选框.




The following code loads XML info to my treeview control. Each node in the treeview has a checkbox.

For Each Record As XElement In doc...<record>
            recordNode = TreeView1.Nodes.Add(Record.Name.ToString)

            For Each Leader As XElement In Record...<leader>

                leaderNode = recordNode.Nodes.Add(Leader.Name.ToString)

                For Each Controlfield As XElement In Record...<controlfield>
                    controlfieldNode = recordNode.Nodes.Add(Controlfield.@tag.ToString)
                Next
            Next
        Next

        For Each Record As XElement In doc...<record>
            recordNode = TreeView1.TopNode
            For Each Datafield As XElement In Record...<datafield>
                datafielNode = recordNode.Nodes.Add(Datafield.@tag.ToString)
                For Each Subfield As XElement In Datafield...<subfield>
                    datafielNode.Nodes.Add(Subfield.@code.ToString)
                Next
            Next
        Next

推荐答案

每个节点都有一个Parent属性.这很简单.

您要做的就是
Every node has a Parent property. This is trivial to do.

All you do is
checkedNode.Parent.Checked = True


其中checkedNode是用户检查的节点.您可以从传递给您的eventargs的代码中获取此信息,具体取决于您正在使用的TreeView事件.


where checkedNode is the node the user checked. You can get this from the eventargs that are passed to you code depending on which TreeView event you''re using.


这篇关于检查Treeview XML子节点,然后检查父节点是否合法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆