以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]目录树问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=83847)

--  作者:pcxjxjhkw
--  发布时间:2016/4/18 16:09:00
--  [求助]目录树问题

有一字典,键为日期型(X年X月),值为字符型。

如何根据字典建目录树,一级节点为:X年,二级节点为X月,三级节点为键值。

 

谢谢


--  作者:大红袍
--  发布时间:2016/4/18 16:18:00
--  
 

Dim dic As new Dictionary(Of String, String)
dic.Add("2015年6月", 1)
dic.Add("2015年7月", 3)
dic.Add("2016年6月", 1)

Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
For Each key As String In dic.Keys
    Dim ary() As String = key.Split("年")
    Dim nd As WinForm.TreeNode
    If trv.Nodes.Contains(ary(0)) = False Then
        nd = trv.Nodes.Add(ary(0))
    Else
        nd = trv.nodes(ary(0))
    End If
    ary(1) = ary(1).Replace("月", "")
    If nd.Nodes.Contains(ary(1)) = False Then
        nd = nd.nodes.Add(ary(1))
    Else
        nd = nd.Nodes(ary(1))
    End If
    If nd.Nodes.Contains(dic(key)) = False Then
        nd = nd.nodes.Add(dic(key))
    Else
        nd = nd.Nodes(dic(key))
    End If
Next


--  作者:pcxjxjhkw
--  发布时间:2016/4/18 16:19:00
--  
谢谢