数据库的一张表怎么样用树型显出来?
[attach]69114[/attach]表名称playlist 表字段Id tvclass tvclassid tvname tvurl 怎么样用树型控件显示出,俺水平有限,请各位老师指点一下
[ 本帖最后由 dafunlang 于 2013-3-5 19:49 编辑 ]
rs.Open "select * from playlist ", Conn, adOpenKeyset, adLockReadOnly Do Until rs.EOF Dim cid As Long cid = rs("tvclassid") Select Case cid Case 0 If Not IsNull(rs("tvclass")) Then Set nodX = TreeView1.Nodes.Add(, , "K" & rs("id"), rs("tvclass")) Else Set nodX = TreeView1.Nodes.Add(, , "K" & rs("id"), "(Null)") End If Case Is > 0 ' Is > 0 ' else ' 有负数?神马情况? If Not IsNull(rs("tvname")) Then Set nodX = TreeView1.Nodes.Add("K" & cid, tvwChild, "K" & rs("id"), rs("tvname")) 'TreeRelationshipConstants tvwChild Else Set nodX = TreeView1.Nodes.Add("K" & cid, tvwChild, "K" & rs("id"), "(Null)") End If End Select rs.MoveNext Loop rs.Close也可以善用 Key。
Private Sub TreeView1_NodeClick(ByVal myNode As Node) Select Case TreeView1.Nodes.Item(TreeView1.SelectedItem.Index).Key Case "id" wmp1.URL = rs("tvurl") End Select End Sub双击节点,tvurl的值,怎么样响应传递给这个wmp1.URL ="",谢谢版主,谢谢楼上的好心人
Private Sub TreeView1_NodeClick(ByVal myNode As MSComctlLib.Node) Dim rs As ADODB.Recordset If Not myNode.Parent Is Nothing Then Set rs = New ADODB.Recordset rs.Open "select * from playlist where id=" & Mid$(myNode.Key, 2), Conn, adOpenKeyset, adLockReadOnly 'wmp1.URL = rs("tvurl") Debug.Print rs("tvurl") rs.Close End If Set rs = Nothing End Sub写这代码时咱想到了2楼。