Dvlpr2878
Dvlpr2878

Reputation: 117

Flattening out a TreeView in WPF

I have some hierarchical that I'd like to display in a TreeView, but formatted to look like a ListBox.

The data I have looks like this (with the possibility of any number of sub levels):

Item 1
  Child 1
  Child 2
Item 2
  Child 3
  Child 4

I'd like the data to be displayed like this (and wrap when need):

Item 1 Child 1 Child 2 Item 2 Child 3 Child 4

I'd like to use the TreeView so I can maintain the relationship between the parent and child items which is why I don't want to use a ListBox. Thanks!

Upvotes: 2

Views: 449

Answers (2)

plinth
plinth

Reputation: 49189

It sounds like the issue you have is that you don't have a clear separation between your data structure and your view. If you have a tree which is not WPF it should be easy to map a tree view onto it. If you have a tree, you can create an tree node numerator that can be used in a list view.

By doing this, the relationship never changes - just how the data is projected in the UI.

Upvotes: 1

David Brunelle
David Brunelle

Reputation: 6440

I think the best way would be to implement a recursive function that will scroll down your tree until it hit the end. That function would take a referenced list or collection as parameter and the current node.

here is the pseudo-code for it

Sub GenerateListFromTree(Node oNode, List oList)

AddItemToList(oNode.Name)

For each Node oChildNode in oNode.Nodes
    GenerateListFromTree(oChildNode,oList)
Next

End Sub

Upvotes: 0

Related Questions