0

我需要创建一个 wpf treeviewlist 看起来像这样:

AAAA

BBBB

....CCCC

....DDDD

.......EEEE

FFFFF

(上面的点是缩进)

我需要从 vb.net (2008) 代码中执行此操作。

我花了很长时间试图弄清楚这一点,到目前为止我所拥有的只是:

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)

任何指针或示例将不胜感激。

谢谢,罗伯

4

2 回答 2

3

你可以很容易地做到这一点。只需将您的子 TreeViewItems 直接添加到父项,就像这样(C#,但很清楚)

var parent = new TreeViewItem();
var child = new TreeViewItem();
parent.Header = "Hey";
child.Header = "There!";
parent.Items.Add(child);
treeView1.Items.Add(parent);
于 2008-12-20T07:07:38.103 回答
1

这是我最终得到的结果,感谢 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))
于 2008-12-20T12:28:31.713 回答