以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  输出TreeView问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=194598)

--  作者:HJG_HB950207
--  发布时间:2024/12/26 7:43:00
--  输出TreeView问题
以下为输出代码:

Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim doc As New PrintDoc \'定义一个报表
For Each nd As WinForm.TreeNode In trv.AllNodes
    Dim rt As New prt.RenderText \'定义一个文本对象
    rt.Text = "".PadLeft(nd.Level * 4) & nd.Text
    
    doc.Body.Children.Add(rt)  
Next
doc.Preview()  

以上输出无各层关系的连接符号“..."":"

请教:如何输出时将各层的连接符号也含其中》

--  作者:有点蓝
--  发布时间:2024/12/26 13:44:00
--  
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim doc As New PrintDoc \'定义一个报表
For Each nd As WinForm.TreeNode In trv.AllNodes
    Dim rt As New prt.RenderText \'定义一个文本对象
    If nd.Level = 0 Then
        rt.Text = nd.Text
    Else
        Dim s As String = ""
        Dim ad As WinForm.TreeNode = nd.ParentNode
        Dim pd As WinForm.TreeNode
        If ad.ParentNode IsNot Nothing Then
            s = "".PadLeft(6)
            pd = ad.ParentNode
        End If 
        Do While pd IsNot Nothing
            If pd.Level > 0 Then
                If pd.Nodes.Count - 1 = ad.Index Then
                    s = "".PadLeft(6) & s
                Else
                    s = "".PadLeft(6) & ":" & s
                End If
            ElseIf trv.Nodes.Count - 1 > pd.Index AndAlso s.StartsWith(":") = False Then
                    s = ":" & s
            End If 
            ad = pd
            pd = pd.ParentNode
        Loop
        rt.Text = s & ":" & "".PadLeft(4, ".") & nd.Text
    End If
    doc.Body.Children.Add(rt) 
Next
doc.Preview()