C#搜索TreeView子节点,保留父节点的方法
程序员文章站
2022-06-30 10:18:52
本文实例讲述了c#搜索treeview子节点,保留父节点的方法。分享给大家供大家参考。具体如下:
c# 搜索treeview子节点保留父节点:
private...
本文实例讲述了c#搜索treeview子节点,保留父节点的方法。分享给大家供大家参考。具体如下:
c# 搜索treeview子节点保留父节点:
private void selectnodebyname(string name) { //重新生生成树, inittvcatalog(); //删除节点 selectnode(tvcatalog.nodes, name); } private void selectnode(treenodecollection nodes, string name) { bool del = true; for (int i = nodes.count - 1; i >= 0; i--) { treenode node = nodes[i]; del = true; if (node.nodes.count != 0) { selectnode(node.nodes, name); } if (node.text.startswith(name, stringcomparison.ordinalignorecase)) { del = false; } else { del = true; } if (del && node.nodes.count == 0) { node.remove(); } } tvcatalog.expandall(); }
wpf搜索treeview子节点保留父节点:
private void selectnodebyname(string name) { //重新生生成树, method = new common.publicmethod(); method.treeviewload(); //删除节点 selectnode(regimesetting.common.staticvariables.treeview.items, name); method = null; } private void selectnode(itemcollection nodes, string name) { bool del = true; for (int i = nodes.count - 1; i >= 0; i--) { treeviewitem node = nodes[i] as treeviewitem; del = true; if (node.items.count != 0) { selectnode(node.items, name); } if (node.header.tostring().startswith(name, stringcomparison.ordinalignorecase)) { del = false; } else { del = true; } if (del && node.items.count == 0) { if ((node.parent as treeviewitem) != null) (node.parent as treeviewitem).items.remove(node); else (node.parent as treeview).items.remove(node); } } (regimesetting.common.staticvariables.treeview.items[0] as treeviewitem).isexpanded = true; }
希望本文所述对大家的c#程序设计有所帮助。