Click here to Skip to main content
16,004,927 members
Home / Discussions / C#
   

C#

 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
maxatlis27-Mar-09 6:11
maxatlis27-Mar-09 6:11 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
maxatlis27-Mar-09 6:27
maxatlis27-Mar-09 6:27 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
musefan27-Mar-09 6:34
musefan27-Mar-09 6:34 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
maxatlis27-Mar-09 6:44
maxatlis27-Mar-09 6:44 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
musefan27-Mar-09 6:49
musefan27-Mar-09 6:49 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
maxatlis27-Mar-09 7:10
maxatlis27-Mar-09 7:10 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
fly90427-Mar-09 7:54
fly90427-Mar-09 7:54 
AnswerRe: Progmatically Creating TreeNodes and Child Nodes Pin
Ian Shlasko27-Mar-09 9:58
Ian Shlasko27-Mar-09 9:58 
Given the nature of trees in general, you might want to simplify things and go for a recursive approach. Something like this (pseudo-code):

InsertURL(TreeNode root, string url)
{
  InsertURL(root, SplitNodes(url), 0)
}

InsertURL(TreeNode parent, string[] urlParts, int index)
{
  TreeNode nextChild = parent.Find(urlParts[index])
  
  If nextChild is not valid
  {
    Create a new node under parent corresponding to urlParts[index]
    nextChild = The new node
  }

  if ++index < urlParts.Length
  {
    InsertURL(nextChild, urlParts, index)
  }
}


(Yes, I know the syntax isn't proper C#. That's intentional, so ya don't try to copy-paste and compile it Smile | :) )

Notes:
1) The array gets passed as a reference, so it's faster to just send the whole array to each recursive call instead of stripping out each part as we place it.
2) Note the ++ in the last comparison. Increment it, THEN see if the new value is in-bounds, then recurse if valid.
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
maxatlis27-Mar-09 13:20
maxatlis27-Mar-09 13:20 
AnswerHow To: - Progmatically Creating TreeNodes and Child Nodes [Answer] Pin
maxatlis27-Mar-09 14:37
maxatlis27-Mar-09 14:37 
QuestionOracle + #C DataBase Picture Pin
E_Gold27-Mar-09 5:17
E_Gold27-Mar-09 5:17 
QuestionNew Line VS2005 Installer's BodyText Pin
jp2code27-Mar-09 5:12
professionaljp2code27-Mar-09 5:12 
Questiondatabase in sql Pin
Mangesh Tomar27-Mar-09 4:39
Mangesh Tomar27-Mar-09 4:39 
AnswerRe: database in sql Pin
musefan27-Mar-09 4:47
musefan27-Mar-09 4:47 
GeneralRe: database in sql Pin
Mangesh Tomar27-Mar-09 5:41
Mangesh Tomar27-Mar-09 5:41 
GeneralRe: database in sql Pin
musefan27-Mar-09 5:48
musefan27-Mar-09 5:48 
QuestionCreating an .msg file Pin
MxIsMe27-Mar-09 2:56
MxIsMe27-Mar-09 2:56 
QuestionReceive "Now Playing" Song Information Pin
give.away27-Mar-09 2:52
give.away27-Mar-09 2:52 
AnswerRe: Receive "Now Playing" Song Information Pin
musefan27-Mar-09 4:52
musefan27-Mar-09 4:52 
GeneralRe: Receive "Now Playing" Song Information Pin
give.away27-Mar-09 5:01
give.away27-Mar-09 5:01 
GeneralRe: Receive "Now Playing" Song Information Pin
musefan27-Mar-09 5:09
musefan27-Mar-09 5:09 
GeneralRe: Receive "Now Playing" Song Information Pin
give.away27-Mar-09 5:39
give.away27-Mar-09 5:39 
GeneralRe: Receive "Now Playing" Song Information Pin
Eddy Vluggen27-Mar-09 5:16
professionalEddy Vluggen27-Mar-09 5:16 
GeneralRe: Receive "Now Playing" Song Information Pin
give.away27-Mar-09 5:33
give.away27-Mar-09 5:33 
GeneralRe: Receive "Now Playing" Song Information Pin
0x3c027-Mar-09 6:09
0x3c027-Mar-09 6:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.