Home>

c#search treeview child node keep parent node:

private void selectnodebyname (string name)
{
  //Regenerate Spanning Tree, inittvcatalog ();
 //Delete the node
 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 search treeview child nodes keep parent node:

private void selectnodebyname (string name)
{
 //Regenerate Spanning Tree, method=new common.publicmethod ();
 method.treeviewload ();
 //Delete the node
 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
  • Previous C # method to refresh the desktop
  • Next C # Anonymous Method Foundation Review