treeview图标问题
我的treeview节点是从表中循环加载到tree树中的,请问要是给每个节点加载不同的图标该如何写?
[解决办法]
您是用什么语句来给节点加载图标的?
[解决办法]
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim SqlAdp1 As SqlDataAdapter
Dim SqlCommString As String
SqlCommString = "select * from sSystemMenu "
SqlAdp1 = New SqlDataAdapter(SqlCommString, ConnectionString)
Dim Dataset1 As New DataSet
SqlAdp1.Fill(Dataset1, "sSystemMenu ")
TreeView1.Nodes.Clear()
CreateTreeNode(TreeView1.Nodes, "0\ ", Dataset1.Tables(0))
TreeView1.ExpandAll()
End Sub
Private Sub CreateTreeNode(ByVal nodes As TreeNodeCollection, ByVal parentid As String, ByVal dt As DataTable)
Dim tmp As String = "[MenuParentCode]= ' " & parentid & " ' "
Dim rows() As DataRow = dt.Select(tmp)
If rows.Length > 0 Then
For i As Integer = 0 To rows.Length - 1
Dim node As New System.Windows.Forms.TreeNode
node.Tag = rows(i)
node.Text = Trim(rows(i).Item( "Name ")) + " [ " + Trim(rows(i).Item( "MenuCode ")) + "] "
node.SelectedImageIndex = rows(i).Item( "SelectPic ")
node.ImageIndex = rows(i).Item( "Pic ")
node.Tag = Trim(rows(i).Item( "MenuCode "))
nodes.Add(node)
CreateTreeNode(node.Nodes, rows(i).Item( "MenuPathCode "), dt) '递归调用
Next
End If