我需要创建一个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)
非常感谢任何指针或示例。
谢谢,Rob
答案 0 :(得分: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);
答案 1 :(得分: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))