以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 目录树生成报错 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=193760) |
-- 作者:weibu -- 发布时间:2024/10/11 11:05:00 -- 目录树生成报错 Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1") trv.GenerateTree("Departments", "Path", "DepartmentName", ".") 以上是生成目录树的代码,path数据如下: 001 001.001 001.001.001 001.001.001.001 001.001.001.002 001.001.002 001.001.002.003 001.001.002.002 001.001.003 001.001.002.001 以下是添加子部门的代码: Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1") If trv.SelectedNode IsNot Nothing Then Dim pd As WinForm.TreeNode = trv.SelectedNode Dim Index As Integer = 1 If pd.Nodes.count >= 1 Then Index = CInt(pd.Nodes(pd.nodes.count - 1).name) + 1 End If Dim nd As WinForm.TreeNode = pd.Nodes.Add(index, "请输入") trv.SelectedNode = nd trv.Select trv.BeginEdit 下方代码的目的是存储新增子节点的信息: Dim ndr As Row = Tables("Departments").AddNew() Dim p As DataRow = pd.DataRow ndr("ParentDepartmentID") = p("DepartmentID") ndr("Level") = p("Level") + 1 ndr("UpdateDate") = Date.Today ndr("UpdatedBy") = rsuser ndr("CompanyId") = 1 End If 下方代码是保存数据的代码:执行下方代码后,会删除上面新增的行,并把赋值存储到新增行上一条数据中。 这个代码哪里错误了 Dim dt As DataTable = DataTables("Departments") 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("Path") = str.TrimEnd(".") ndr("DepartmentName") = nd.Text Next dt.DeleteFor("_Identify not in (" & idxs & ")") DataTables("Departments").Save() 同时在部门表的DataRowAdded有如下代码: e.DataRow.save e.DataRow("DepartmentID") = e.DataRow("_Identify") |
-- 作者:有点蓝 -- 发布时间:2024/10/11 11:43:00 -- 请上传实例测试 |