大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
''' summary
我们提供的服务有:成都网站设计、成都做网站、微信公众号开发、网站优化、网站认证、青云谱ssl等。为上1000+企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的青云谱网站制作公司
''' 加入菜单子节点
''' /summary
''' param name="tbMenu"菜单表/param
''' param name="tvNode"父节点/param
''' remarks/remarks
Private Sub AddNode(ByVal tbMenu As DataTable, ByVal tvNode As TreeNode)
Dim myRow As DataRow() = tbMenu.Select(String.Format("PRMENUID = '{0}'", tvNode.NodeID), "SORTORDER")‘查询子菜单,按SORTORDER字段排序
Dim strURL As String = String.Empty‘菜单链接
For Each DataRow In myRow’循环所有子菜单
Dim MainMenuNode As TreeNode = New TreeNode() With {.Text = DataRow.Item("VALUE"), .NodeID = DataRow.Item("MENU_ID")}'实例化一个子节点
If DataRow.Item("URL").ToString.Length 0 Then
strURL = String.Format("{0}?menuid={1}", DataRow.Item("URL"), DataRow.Item("MENUID"))’菜单链接
MainMenuNode.NavigateUrl = strURL
MainMenuNode.IconUrl = "../image/leaf.gif"‘菜单图标
End If
MainMenuNode.SingleClickExpand = True’设置单击菜单时展开子菜单
MainMenuNode.Expanded = True‘默认展开所有菜单
tvNode.Nodes.Add(MainMenuNode)’将子节点添加进父节点
AddNode(tbMenu, MainMenuNode) '利用递归生成树形菜单
Next
End Sub
希望对你有帮助。
说实话一般不是你这样存储的,一般是用一个字段存储ID号,然后用另一个字段存储上级单位的ID号,然后用递归函数生成TreeView。建议你增加一个字段,然后将编号解析出的上级单位存储在里面。以下是我的一个程序用的递归函数:
表名是unit,其中包含了单位名称unit_name,编号unit_id,Unit_upper就是上级单位的id号。
调用方式是 addtree(ds1, TreeView1.Nodes, 0),其中ds1是一个DataSet,对应单位的表,treeview1是控件名称,0是固定值,与表中根节点部门的Unit_upper一致(这个单位没有上级)。
Public Function addtree(ByVal ds As DataSet, ByVal treename As TreeNodeCollection, ByVal x1 As Integer) As Boolean
Dim dt As DataTable = ds.Tables("unit")
Dim dm As BindingManagerBase = Me.BindingContext(ds, "unit")
Dim dr As DataRow() = dt.Select("unit_upper=" x1.ToString)
Dim dr1 As DataRow
Dim nd As TreeNode
Dim nd1 As TreeNode
Dim x2 As Integer
If dr.GetLength(0) 0 Then
For Each dr1 In dr
nd = treename.Add(dr1("unit_name"))
nd.Tag = (dr1("unit_id"))
x2 = treename.IndexOf(nd)
addtree(ds, treename.Item(x2).Nodes, dr1("unit_id"))
Next
End If
Return True
End Function
给你一段我曾经写的代码,主要是生成TreeView的节点!有什么不懂的地方你就提!
Public Sub InitializeTreeView(ByVal strvXL As TreeView, ByVal vrsRecordTwo As DataSet)
Dim treBaseNodeOne As TreeNode
Dim treBaseNodeTwo As TreeNode
Dim strDWDM As String
m_rsRecordTwo = g_clsSybase.SelectSC_PD_SBCSB1()
'查找供电局信息
g_clsSybase.SelectRS_ZZJG_ZZJGDMB(m_rsRecordOne)
'添加根节点
Do While m_rsRecordOne.Read
strDWDM = m_rsRecordOne.GetString(0) '获取单位代码
treBaseNodeOne = New TreeNode
treBaseNodeOne.Text = m_rsRecordOne.GetString(1).Trim() '获取单位名称
treBaseNodeOne.Name = m_rsRecordOne.GetString(1)
treBaseNodeOne.Tag = ""
strvXL.Nodes.Add(treBaseNodeOne)
'添加树结构第二层
Dim drsTwo() As DataRow
drsTwo = m_rsRecordTwo.Tables(0).Select("SSDW='" strDWDM "' and SC__XLBM is null")
For Each dr As DataRow In drsTwo
treBaseNodeTwo = New TreeNode
treBaseNodeTwo.Text = dr.Item("XLMC").ToString.Trim
treBaseNodeTwo.Name = dr.Item("XLMC")
treBaseNodeTwo.Tag = dr.Item("XLBM")
treBaseNodeOne.Nodes.Add(treBaseNodeTwo)
Next
Loop
m_rsRecordOne.Close()
End Sub