VB.NET中的treeview控件
发布网友
发布时间:2022-05-07 11:13
我来回答
共3个回答
热心网友
时间:2023-10-28 11:49
''' <summary>
''' 加入菜单子节点
''' </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
希望对你有帮助。追问怎么这么复杂?
我只要获取控件中的节点数量就够了
热心网友
时间:2023-10-28 11:50
先通过测试节点的个数 然后获取最后一个节点对象,最后创建子节点追问能不能把代码放上来..
热心网友
时间:2023-10-28 11:50
Dim TreeNode1 As TreeNode = New TreeNode("节点1")
Dim TreeNode2 As TreeNode = New TreeNode("节点0", New System.Windows.Forms.TreeNode() {TreeNode1})
TreeNode1.Name = "节点1"
TreeNode1.Text = "节点1"
TreeNode2.Name = "节点0"
TreeNode2.Text = "节点0"
TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {TreeNode2})追问那怎么获取所有节点的总数量?
追答treeviewe1.nodes.count
热心网友
时间:2023-10-28 11:49
''' <summary>
''' 加入菜单子节点
''' </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
希望对你有帮助。追问怎么这么复杂?
我只要获取控件中的节点数量就够了
热心网友
时间:2023-10-28 11:50
先通过测试节点的个数 然后获取最后一个节点对象,最后创建子节点追问能不能把代码放上来..
热心网友
时间:2023-10-28 11:50
Dim TreeNode1 As TreeNode = New TreeNode("节点1")
Dim TreeNode2 As TreeNode = New TreeNode("节点0", New System.Windows.Forms.TreeNode() {TreeNode1})
TreeNode1.Name = "节点1"
TreeNode1.Text = "节点1"
TreeNode2.Name = "节点0"
TreeNode2.Text = "节点0"
TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {TreeNode2})追问那怎么获取所有节点的总数量?
追答treeviewe1.nodes.count
热心网友
时间:2023-10-28 11:49
''' <summary>
''' 加入菜单子节点
''' </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
希望对你有帮助。追问怎么这么复杂?
我只要获取控件中的节点数量就够了
热心网友
时间:2023-10-28 11:50
先通过测试节点的个数 然后获取最后一个节点对象,最后创建子节点追问能不能把代码放上来..
热心网友
时间:2023-10-28 11:50
Dim TreeNode1 As TreeNode = New TreeNode("节点1")
Dim TreeNode2 As TreeNode = New TreeNode("节点0", New System.Windows.Forms.TreeNode() {TreeNode1})
TreeNode1.Name = "节点1"
TreeNode1.Text = "节点1"
TreeNode2.Name = "节点0"
TreeNode2.Text = "节点0"
TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {TreeNode2})追问那怎么获取所有节点的总数量?
追答treeviewe1.nodes.count