日期:2014-05-17 浏览次数:20392 次
private void tvDevice_BeforeExpand(object sender, TreeViewCancelEventArgs e) { if (e.Action != TreeViewAction.Unknown) { //这里循环折叠其余节点 } }
------解决方案--------------------
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) { //TreeView1.SelectedNode.ToggleExpandState(); TreeView1.CollapseAll(); TreeView1.SelectedNode.Expand(); TreeNode node = TreeView1.SelectedNode; while (node.Parent != null) { node.Parent.Expand(); node = node.Parent; } }
------解决方案--------------------
protected void Treeview1_TreeNodeExpanded(object sender, TreeNodeEventArgs e) { if (e.Node.Depth != 0) { foreach (TreeNode item in Treeview1.Nodes) { if (e.Node.Value == item.Value) { item.Expand(); } else { item.Collapse(); } } } }