首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

共享:怎么高效使用Treeview中的Checkbox

2012-09-23 
共享:如何高效使用Treeview中的CheckboxVB.NET code向下递归Private Sub foreward(ByVal parent As TreeN

共享:如何高效使用Treeview中的Checkbox

VB.NET code
'向下递归    Private Sub foreward(ByVal parent As TreeNode)        For Each child As TreeNode In parent.Nodes            If child IsNot Nothing Then                child.Checked = parent.Checked                foreward(child)            End If        Next    End Sub    '向上递归    Private Sub backward(ByVal child As TreeNode)        Select Case child.Level            Case Is > 0                Dim b As Boolean = True                For Each Node As TreeNode In child.Parent.Nodes                    If Node IsNot Nothing Then b = b And Node.Checked                Next                child.Parent.Checked = b                backward(child.Parent)        End Select    End Sub    '点击后此过程只许运行一次!    Private only As Boolean = True    Private Sub TreeView_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck        If Not only Then Return        only = False        foreward(e.Node)        backward(e.Node)        only = True    End Sub


不知道大家有没有更好的的建议。

[解决办法]
分享了
[解决办法]
好象afterCheck事件会自动向下连续触发

for each n as treenode in e.node.nodes
n.checked=e.node.checked
next

热点排行