本文整理汇总了VB.NET中System.Windows.Forms.TreeView.BeforeCollapse事件的典型用法代码示例。如果您正苦于以下问题:VB.NET TreeView.BeforeCollapse事件的具体用法?VB.NET TreeView.BeforeCollapse怎么用?VB.NET TreeView.BeforeCollapse使用的例子?那么恭喜您, 这里精选的事件代码示例或许可以为您提供帮助。您也可以进一步了解该事件所在类System.Windows.Forms.TreeView
的用法示例。
在下文中一共展示了TreeView.BeforeCollapse事件的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: CheckForCheckedChildren
Private Sub showCheckedNodesButton_Click(ByVal sender As Object, ByVal e As EventArgs)
' Disable redrawing of treeView1 to prevent flickering
' while changes are made.
treeView1.BeginUpdate()
' Collapse all nodes of treeView1.
treeView1.ExpandAll()
' Add the CheckForCheckedChildren event handler to the BeforeExpand event.
AddHandler treeView1.BeforeCollapse, AddressOf CheckForCheckedChildren
' Expand all nodes of treeView1. Nodes without checked children are
' prevented from expanding by the checkForCheckedChildren event handler.
treeView1.CollapseAll()
' Remove the checkForCheckedChildren event handler from the BeforeExpand
' event so manual node expansion will work correctly.
RemoveHandler treeView1.BeforeCollapse, AddressOf CheckForCheckedChildren
' Enable redrawing of treeView1.
treeView1.EndUpdate()
End Sub
' Prevent collapse of a node that has checked child nodes.
Private Sub CheckForCheckedChildren(ByVal sender As Object, ByVal e As TreeViewCancelEventArgs)
If HasCheckedChildNodes(e.Node) Then
e.Cancel = True
End If
End Sub
' Returns a value indicating whether the specified
' TreeNode has checked child nodes.
Private Function HasCheckedChildNodes(ByVal node As TreeNode) As Boolean
If node.Nodes.Count = 0 Then
Return False
End If
Dim childNode As TreeNode
For Each childNode In node.Nodes
If childNode.Checked Then
Return True
End If
' Recursively check the children of the current child node.
If HasCheckedChildNodes(childNode) Then
Return True
End If
Next childNode
Return False
End Function 'HasCheckedChildNodes