🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.pl.comp.lang.csharp
Article #10038

Re: Zachowanie stanu w TreeView

#10038
From: Wiktor Zychla
Date: Wed, 16 Nov 2005 22:43
56 lines
2730 bytes
> A czy moglbys "zapodac" jakis kawalek algorytmu z odrobinka funkcji 
> rekurencyjnej do takiego spacerku po TreeView, ktory uwazasz za 
> najbardziej optymalny ( w sensie szybkosci wykonania, z uwzglednieniem 
> przejscia po wszystkich wezlach ) ? Mam w swoim projekcie pare tysiakow 
> wezlow, i wolalbym nie robic z tego fragmentu kodu "piety Achillesa". 
> Strasznie bys mi pomogl.

nie musisz chodzić po wszystkich węzłach drzewa, tylko po wszystkich węzłach 
danego poziomu. nawet jak drzewo jest duże, to jeden poziom nie powinien 
mieć zbyt dużo węzłów. funkcja nie jest rekurencyjna, zwykły for.

Wiktor Zychla

  public static void TreeNode_FindAndSelectNode( TreeView treeView, string 
nodePath )
  {
   string[] nodePathPart = nodePath.Split( new char[] {'\\'} );

   TreeNode tSearchNode = null;
   TreeNode tSearchLevel = null;

   foreach ( TreeNode t in treeView.Nodes )
    if ( t.Text == nodePathPart[0] )
    {
     tSearchNode = t;
     tSearchNode.EnsureVisible();
     tSearchNode.Expand();
     break;
    }

   if ( tSearchNode != null )
    for ( int iLevel=1; iLevel<nodePathPart.Length; iLevel++ )
    {
     tSearchLevel = null;
     foreach ( TreeNode tC in tSearchNode.Nodes )
      if ( tC.Text == nodePathPart[iLevel] )
      {
       tSearchLevel = tC;
       tSearchLevel.EnsureVisible();
       tSearchLevel.Expand();
       break;
      }

     if ( tSearchLevel != null )
     {
      tSearchNode = tSearchLevel;
     }
     else
      break;
    }
   if ( tSearchNode != null )
   {
    tSearchNode.EnsureVisible();
    treeView.SelectedNode = tSearchNode;
   }
  }
Technical Details
Message-ID: <dlgcmv$4tr$1@atlantis.news.tpi.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.gazeta.pl!news.nask.pl!news.nask.org.pl!newsfeed.tpinternet.pl!atlantis.news.tpi.pl!news.tpi.pl!not-for-mail
References: <dlf3ot$gkm$1@inews.gazeta.pl> <dlf5vq$ahk$1@nemesis.news.tpi.pl> <dlg7sm$mf5$1@inews.gazeta.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.gazeta.pl!news.nask.pl!news.nask.org.pl!newsfeed.tpinternet.pl!atlantis.news.tpi.pl!news.tpi.pl!not-for-mail
From: "Wiktor Zychla" <user@nospam.com.eu>
Newsgroups: alt.pl.comp.lang.csharp
Subject: Re: Zachowanie stanu w TreeView
Date: Wed, 16 Nov 2005 23:43:27 +0100
Organization: tp.internet - http://www.tpi.pl/
Lines: 58
Message-ID: <dlgcmv$4tr$1@atlantis.news.tpi.pl>
References: <dlf3ot$gkm$1@inews.gazeta.pl> <dlf5vq$ahk$1@nemesis.news.tpi.pl> <dlg7sm$mf5$1@inews.gazeta.pl>
NNTP-Posting-Host: bwx213.internetdsl.tpnet.pl
X-Trace: atlantis.news.tpi.pl 1132181023 5051 83.18.231.213 (16 Nov 2005 22:43:43 GMT)
X-Complaints-To: usenet@tpi.pl
NNTP-Posting-Date: Wed, 16 Nov 2005 22:43:43 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Response
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit