我需要以最小的复杂度检查/选择树视图中的所有节点。我的树视图有3个级别,其中有许多节点。 下面是我的代码:
<asp:TreeView ID="TreeView1" runat="server" DataSourceID="XmlDataSource1" ShowCheckBoxes="All" ShowExpandCollapse="true"
<DataBindings>
<asp:TreeNodeBinding DataMember="Category" TextField="Name"
ValueField="Value" />
<asp:TreeNodeBinding DataMember="LeafCategory" TextField="Name"
ValueField="Value" />
<asp:TreeNodeBinding DataMember="ChildCategory" TextField="Name"
ValueField="Value" />
<asp:TreeNodeBinding DataMember="SubCategory" TextField="Name"
ValueField="Value" />
<asp:TreeNodeBinding DataMember="Categories" TextField="Name"
ValueField="Value" />
</DataBindings>
</asp:TreeView>
答案 0 :(得分:1)
这样的事情:
Private Sub SetMyChildren(ByVal parentNode As TreeNode, ByVal isChecked As Boolean, ByVal isSelected As Boolean)
parentNode.Checked = isChecked
parentNode.Selected = isSelected
For Each child As TreeNode In parentNode.ChildNodes
SetMyChildren(child, isChecked, isSelected)
Next
End Sub
'f.e. set all nodes from complete TreeView to checked and selected:
For Each node As TreeNode In TreeView1.Nodes
SetMyChildren(node, True, True)
Next