以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 目录树不限级生成优化,如果不生产多余行 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=150431) |
-- 作者:weibu -- 发布时间:2020/5/29 18:58:00 -- 目录树不限级生成优化,如果不生产多余行 老师这段代码如何优化,不是生成多行再删除,而是仅生成一条数据 Dim dt As DataTable = DataTables("department") Dim dic As New Dictionary(of Integer, Integer) Dim prevLevel As Integer = 0 Dim idxs As String = "-1," For Each nd As WinForm.TreeNode In e.Form.Controls("TreeView1").AllNodes If nd.Level = 0 AndAlso dic.count > 0 Then Dim temp = dic(0) dic.Clear dic.Add(0, temp) End If If dic.ContainsKey(nd.Level) = False Then dic.Add(nd.Level, 1) Else dic(nd.Level) = dic(nd.Level) + 1 End If For i As Integer = nd.level + 1 To prevLevel dic(i) = 0 Next prevLevel = nd.Level Dim ndr As DataRow If nd.DataRow IsNot Nothing Then ndr = dt.Find("_Identify = " & nd.DataRow("_Identify")) Else ndr = dt.AddNew End If idxs &= ndr("_Identify") & "," Dim str As String = "" For i As Integer = 0 To nd.Level str &= format(dic(i), "000") & "." Next ndr("departno") = str.TrimEnd(".") ndr("department") = nd.Text Next dt.DeleteFor("_Identify not in (" & idxs & ")")
|
-- 作者:有点蓝 -- 发布时间:2020/5/30 8:42:00 -- http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&Id=122759 |