views:

1547

answers:

2

I need to create a wpf treeviewlist to look something like this:

AAAA

BBBB

....CCCC

....DDDD

.......EEEE

FFFFF

(where the dots above are indents)

I need to do this from vb.net (2008) code.

I've spent an embarrassingly long amount of time trying to figure this out, and so far all I’ve got is:

vb.net:

Dim tvi1, tvi2 As TreeViewItem

tvi1 = New TreeViewItem

tvi2 = New TreeViewItem

Dim Node1 As Integer

tvi1.Header = "AAAA"

tvi2.Header = "BBBB"

Node1 = TreeView1.Items.Add(tvi1)

Node1 = TreeView1.Items.Add(tvi2)

Any pointers or examples would be greatly appreciated.

Thanks, Rob

+1  A: 

You can do it quite easily. Simply add your child TreeViewItems directly to the parent item, like so (C#, but very clear)

var parent = new TreeViewItem();
var child = new TreeViewItem();
parent.Header = "Hey";
child.Header = "There!";
parent.Items.Add(child);
treeView1.Items.Add(parent);
Pwninstein
Thank you, that got me going in the rght directon
Rob
+1  A: 

Here is what I ended up with, thanks Pwninstein:

        Dim Node(5) As TreeViewItem

        For x As Int16 = 0 To 5
            Node(x) = New TreeViewItem
        Next

        Node(0).Header = "AAAA"
        TreeView1.Items.Add(Node(0))

        Node(1).Header = "BBBB"
        TreeView1.Items.Add(Node(1))

        Node(2).Header = "CCCC"
        Node(1).Items.Add(Node(2))

        Node(3).Header = "DDDD"
        Node(1).Items.Add(Node(3))

        Node(4).Header = "EEEE"
        Node(3).Items.Add(Node(4))

        Node(5).Header = "FFFF"
        TreeView1.Items.Add(Node(5))
Rob