您如何针对两个不同的动作对树视图执行递归调用? [英] How could you perform a recursive call for a treeview for two different actions?

查看:62
本文介绍了您如何针对两个不同的动作对树视图执行递归调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我在所有驱动器的目录中都有一个树状视图,包括复选框(Netframework 2.0).当我检查一个节点时,下面的以下过程将检查被检查节点的所有子节点.因此,我在Treeview1_AfterCheck事件过程内部调用了该过程.但是,我的目的还在于检查标记有驱动程序名称的节点,例如(C:\,D:\也许是E:\或其他名称).当我这样做时,由于递归调用,我得到了stackoverflow错误.您如何一次执行两项操作来检查主节点(驱动程序名称),而另一节点下的节点又检查了一个呢?我必须以某种方式摆脱CheckRootNode过程.任何示例代码都将不胜感激.

谢谢.

<br /><br />    ''<br />    ''This procedure checks the root node of any child under it<br />    ''<br />    Private Sub CheckRootNode(ByVal GetNode As TreeNode)<br /><br />        Do While Not GetNode.Parent Is Nothing<br /><br />            Root = GetNode.Parent<br />            CheckRootNode(Root)<br />        Loop<br /><br />        TreeView1.Nodes(Root.Index).Checked = True<br />    End Sub<br /><br />    ''<br />    ''This procedure checks all the child nodes of the parent<br />    ''<br />    Private Sub CheckChildNodes(ByVal GetParentNode As TreeNode, ByVal CheckState As Boolean)<br /><br />        For Each xnode As TreeNode In GetParentNode.Nodes<br />            xnode.Checked = CheckState<br />        Next<br /><br />    End Sub<br />




<br /><br />Private Sub TreeView1_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck<br /><br />        Call CheckChildNodes(e.Node, e.Node.Checked)<br />        Call CheckRootNode(e.Node)<br />End Sub<br />


解决方案

您的问题是检查状态更改时触发的事件正在设置检查状态.添加一个布尔值,并使用它来阻止CheckChildNodes中触发的事件导致从事件处理程序中再次调用CheckChildNodes.


Hi,

I have a treeview within directories of all drives including checkboxes (Netframework 2.0) When I check one node the following procedure below checks all the childs of the checked node. Therefore I have called the procedure inside the Treeview1_AfterCheck event procedure. But my aim is also to also check the node which is tagged with a driver name such as (C:\, D:\ maybe E:\ or something else). When I do that I am getting stackoverflow error because of recursive calls. How could you perform both actions at once to check the main node (driver name) and the nodes under the other checked one? Somehow I have to get rid of CheckRootNode procedure. Any sample code will be appreciated.

Thanks.

<br /><br />    ''<br />    ''This procedure checks the root node of any child under it<br />    ''<br />    Private Sub CheckRootNode(ByVal GetNode As TreeNode)<br /><br />        Do While Not GetNode.Parent Is Nothing<br /><br />            Root = GetNode.Parent<br />            CheckRootNode(Root)<br />        Loop<br /><br />        TreeView1.Nodes(Root.Index).Checked = True<br />    End Sub<br /><br />    ''<br />    ''This procedure checks all the child nodes of the parent<br />    ''<br />    Private Sub CheckChildNodes(ByVal GetParentNode As TreeNode, ByVal CheckState As Boolean)<br /><br />        For Each xnode As TreeNode In GetParentNode.Nodes<br />            xnode.Checked = CheckState<br />        Next<br /><br />    End Sub<br />




<br /><br />Private Sub TreeView1_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck<br /><br />        Call CheckChildNodes(e.Node, e.Node.Checked)<br />        Call CheckRootNode(e.Node)<br />End Sub<br />



解决方案

Your issue is that the event fired when the check state changes, is setting the check state. Add a boolean, and use it to stop the event fired in CheckChildNodes from causing CheckChildNodes to be called again from the event handler.


这篇关于您如何针对两个不同的动作对树视图执行递归调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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