2010-05-20 1 views
2

Je dois vérifier/sélectionner tous les nœuds dans une arborescence avec une complexité minimale. Ma vue arborescente comporte 3 niveaux et plusieurs nœuds. ci-dessous est mon code:Comment vérifier tous les nœuds dans l'arborescence avec une complexité minimale

<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> 

Répondre

1

Quelque chose comme ceci:

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