不需要递归,也不需要判断规则:
Dim tv As WinForm.TreeView = e.Form.Controls("TreeView科目表")
tv.StopRedraw
Dim t As Table = Tables("科目表")
t.Sort = "科目代码"
Dim lst As New List(Of Integer)
For Each r As Row In t.Rows
If lst.Contains(r("科目代码").Length) = False Then
lst.Add(r("科目代码").Length)
End If
Next
lst.Sort
tv.Nodes.Clear
For Each r As Row In t.Rows
If tv.Nodes.Contains(r("科目代码")) = False Then
tv.Nodes.Add(r("科目代码"),r("科目名称"))
End If
Next
For Each nd As WinForm.TreeNode In tv.AllNodes
For i As Integer = 1 To lst.Count - 1
If nd.Name.Length = lst(i) Then
For j As Integer = 0 To i - 1
nd.MoveRight
Next
End If
Next
Next
tv.CollapseAll
tv.ResumeRedraw
[此贴子已经被作者于2014-8-11 18:10:58编辑过]