问个简单的小问题
TreeView每个子节点能否依需求改变不同的背景颜色?
Private Sub Form_Load() Dim i As Integer Set node1 = TreeView1.Nodes.Add(, , "school", "学校") Set node2 = TreeView1.Nodes.Add(node1.Index, tvwChild, "section", "部门") Set node3 = TreeView1.Nodes.Add(node2.Index, tvwChild, "department", "院系") Set node4 = TreeView1.Nodes.Add(node2.Index, tvwChild, "excute", "行政") Set node5 = TreeView1.Nodes.Add(node2.Index, tvwChild, "logistics", "后勤") For i = 1 To 10 Set node5 = TreeView1.Nodes.Add(node3.Index, tvwChild, "AAA" & i, "电子系" & i) Next i End Sub
Option Explicit Private Sub Command1_Click() Dim nodx As Node Dim n As Long '父节点,这里是演示,可以以参数形式传入 Set nodx = TreeView1.Nodes.Item("d89") '获取第一个子节点的文本,并将 N 设置为它的索引值。 n = nodx.Child.Index '若 N 不是子节点的最后相邻节点的索引 While n <> nodx.Child.LastSibling.Index TreeView1.Nodes.Item(n).BackColor = vbGreen '设置背景颜色 '重置 N 为下一个相邻节点的索引。 n = TreeView1.Nodes(n).Next.Index Wend TreeView1.Nodes.Item(n).BackColor = vbGreen '补上最后一个的背景颜色 End Sub Private Sub Form_Load() TreeView1.BorderStyle = 1 '确保边界是可视的。 Dim nodx As Node Set nodx = TreeView1.Nodes.Add(, , "d", "Dates") Set nodx = TreeView1.Nodes.Add("d", tvwChild, "d89", "1989") Set nodx = TreeView1.Nodes.Add("d", tvwChild, "d90", "1990") '创建 1989 节点的子节点。 Set nodx = TreeView1.Nodes.Add("d89", tvwChild, , "John") Set nodx = TreeView1.Nodes.Add("d89", tvwChild, , "Brent") Set nodx = TreeView1.Nodes.Add("d89", tvwChild, , "Eric") Set nodx = TreeView1.Nodes.Add("d89", tvwChild, , "Ian") nodx.EnsureVisible '显示所有节点。 '创建 1990 节点的子节点。 Set nodx = TreeView1.Nodes.Add("d90", tvwChild, , "Randy") Set nodx = TreeView1.Nodes.Add("d90", tvwChild, , "Ron") nodx.EnsureVisible '显示所有节点。 End Sub
For i = 0 To UBound(Selected) If Selected(i) <> "" Then For j = 1 To ProjManagerTreeView.Nodes.Count If (InStr(Selected(i), "True") <> 0) And (ProjManagerTreeView.Nodes(j).Text = Mid(Selected(i), 1, InStr(Selected(i), ",") - 1)) Then ProjManagerTreeView.Nodes(j).BackColor = vbRed End If Next j End If Next i