目录树更具表和导航页面内容生成
提示的错误信息是:
错误所在事件:窗口,用户授权,TreeView1,AfterSelectNode
详细错误信息:
未将对象引用设置到对象的实例。
生成目录树代码:
Dim yh As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim ck As WinForm.TreeView = e.Form.Controls("TreeView2")
Dim dhc As WinForm.TopicBar = Forms("导航栏").Controls("TopicBar1")
'导航页面目录树
For Each page As WinForm.TopicPage In dhc.Pages
If ck.Nodes.Contains(page.Name) = False Then
ck.Nodes.Add(page.Name)
End If
For Each link As WinForm.TopicLink In page.Links
ck.Nodes(page.Name).Nodes.Add(link.Text.trim("←"))
Next
Next
yh.BuildTree("用户_用户表","用户名")
ck.ExpandAll
ck.Nodes(0).Collapse
左边目录树AfterSelectNode代码:
Dim trv1 As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim trv2 As WinForm.TreeView = e.Form.Controls("TreeView2")
Dim mc As String = "& e.Node.Name &"
Dim drs As List(Of DataRow) = DataTables("用户_授权").Select("用户 like '*"& e.Node.Name &"*'")
'选择不同行时清除选择状态
For Each nd As WinForm.TreeNode In trv2.AllNodes
nd.Checked = False
Next
For Each dr1 As DataRow In DataTables("用户_授权").Select("用户 like '*"& e.Node.Name &"*' and 子节点 is null")
trv2.Nodes(dr1("父节点")).Checked = dr1.IsNull("父节点") = False AndAlso dr1.IsNull("子节点") = True
Next
For Each dr2 As DataRow In DataTables("用户_授权").Select("用户 like '*"& e.Node.Name &"*' and 子节点 is not null")
trv2.Nodes(dr2("父节点")).Nodes(dr2("子节点")).Checked = dr2.IsNull("父节点") = False AndAlso dr2.IsNull("子节点") = False
Next
右边目录树AfterCheckNode代码:
Dim trv1 As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim trv2 As WinForm.TreeView = e.Form.Controls("TreeView2")
Dim nd1 As WinForm.TreeNode = trv1.SelectedNode
Dim nd2 As WinForm.TreeNode = trv2.SelectedNode
Dim dr As DataRow
Dim sl As Integer
If nd2.Level = 0 Then
dr = DataTables("用户_授权").Find("父节点 = '"& e.Node.Name &"'")
ElseIf nd2.Level = 1 Then
dr = DataTables("用户_授权").Find("父节点 = '"& e.Node.ParentNode.Name &"' and 子节点 = '"& e.Node.Name &"'")
End If
If e.Node.IsSelected = True
If dr("用户").contains(nd1.Text) = False
If dr.IsNull("用户")
dr("用户") = nd1.Text
Else
dr("用户") = dr("用户") & "," & nd1.Text
End If
ElseIf e.Node.Checked = False
Dim ss() As String = dr("用户").split(",")
Dim lst As new List(of String)
lst.AddRange(ss)
lst.remove(nd1.Text)
dr("用户") = String.Join(",",lst.ToArray())
End If
End If