Ken

Ken

  • NA
  • 110
  • 0

Is there a way to build string showing a TreeView hierarchical struct?

May 3 2021 7:01 AM
I have a treeview and it's used for managing the folders/programs in a systray program launcher I made.  I wanted to add a way to move multiple programs to other parent folders easily.  I figured no big deal, I'll make the TreeView allow multiple selection, that's not an issue right?  Welllll apparently it is.  So I figured OK, I'll build a little popup window that asks you to select the parent for the items then have a listbox that shows all the available nodes and you select what you want.  Easy peasy.
 
However...  I can't figure out the right way to build my listbox items.  Say I have a treeview with these nodes: 
  1. Apps  
  2. |__FileZilla  
  3. |__Outlook  
  4. Media  
  5. |__Photoshop  
  6. |__Audacity  
  7. |__Video  
  8.     |__ZoomPlayer  
  9.     |__VLC  
I want my resultant listbox to have:
  1. Apps\FileZilla  
  2. Apps\Outlook  
  3. Media\Photoshop  
  4. Media\Audacity  
  5. Media\Video\ZoomPlayer  
  6. Media\Video\VLC  
I see the TreeNodes have a Parent property so I figured I'd make a method I can call that calls itself and builds the list.  To make a long story short; it was a hot mess, lol.  Did not work well.  I just can't wrap my head around the correct process/flow.
 
Each TreeNode's Tag is a wrapper "Node" which has a property to determine if it's a folder or a program. I figure I can check that as I iterate the nodes and check if ((Node)treeNode.Tag).NodeClass == NodeClasses.Folder then I know I don't have to add it to the listbox.
 
Can someone assist?  Thanks! 
 
PS on a tangent here, but out of curiosity...  that NodeClasses enum, my Java teacher said enum properties should be UPPERCASE.  I see in most code examples in C# they are PascalCase.  Is that the accepted standard for C#?  I really don't like all caps so I avoided it.  Just curious if that's against naming conventions or not. 

Answers (3)