数据结构如下:
商品类别编号 商品类别名称 所属商品类别编号
1 日化用品 0
2 茶 0
3 化装品 1
4 绿茶 2
5 高级绿茶 4
6 中级绿茶 4我要把这些类别按照树形结构在treeview中显示出来请大家帮帮忙
商品类别编号 商品类别名称 所属商品类别编号
1 日化用品 0
2 茶 0
3 化装品 1
4 绿茶 2
5 高级绿茶 4
6 中级绿茶 4我要把这些类别按照树形结构在treeview中显示出来请大家帮帮忙
解决方案 »
- 我用API函数GetClassName找到了DVD控件MsWebdvd.dll的句柄hWnd,目的是使播放窗口响应我的鼠标输入。可是事与愿违,出重大问题了:
- vb生成的exe文件可以运行,可是datagrid中提取不出来数据
- 高手过招:如何在VB中实现改变DNS解析地址-->>
- 如何将Combo控件做成“键-值”对应的?
- 请问一些vb的问题,第2个问题实在是找不出原因了,求救!
- 关于使用WEBBROWSER share session的问题
- 有关com的问题,请大家帮忙!
- 急需源代码,vb的计算器源代码
- 听说这里有许多的高手,我想好好的学VB,自己有电脑,希望能给个建议,先学那本书比较好!谢谢!
- DataGrid控件问题再次重出,高手请显出真本事来!水猫,不哭水笑快站出来再看看!
- 求助!vb shell问题
- 关于在登录窗口使用winsock的问题,应该很简单~~
' Populate our TreeView Control with the Data from our Product database
'
Dim lCount As Long
'Dim rsSections As DAO.Recordset
Dim rsSections As ADODB.Recordset
Dim sParent As String
Dim sKey As String
Dim sText As String
Dim bBookMark As Boolean
Dim nNode As Node
Dim strSQL As String
Dim sData() As String
Dim lList As Long strSQL = "Select * From tblProduct Order By tblProduct.所属商品类别编号"
'Set rsSections = mDB.OpenRecordset(strSQL, dbOpenSnapshot)
Set rsSections = New ADODB.Recordset
With rsSections
.Open strSQL, mADODBConnection, ADODB.adOpenKeyset, ADODB.adLockOptimistic
End With Set tvProduct.ImageList = Nothing
Set tvProduct.ImageList = ImageList1 If rsSections.BOF And rsSections.EOF Then
tvProduct.Nodes.Add , , "ROOT", "My Company", "VIEWBOOKMARKS"
BoldTreeNode tvProduct.Nodes("ROOT")
Exit Sub
End If TreeRedraw tvProduct.hWnd, False rsSections.MoveFirst
Set tvProduct.ImageList = Nothing
Set tvProduct.ImageList = ImageList1
'
' Populate the TreeView Nodes
' With tvProduct.Nodes
.Clear
.Add , , "ROOT", "My Company", "VIEWBOOKMARKS"
'
' Make our Root Item BOLD
'
BoldTreeNode tvProduct.Nodes("ROOT")
'
' Now add all nodes into TreeView, but under the root item.
' We reparent the nodes in the next step
'
lList = 1
ReDim sData(1 To lList) Do Until rsSections.EOF
sParent = rsSections("所属商品类别编号").Value
sKey = rsSections("商品类别编号").Value
sText = rsSections("商品类别名称").Value Set nNode = .Add("ROOT", tvwChild, "C" & sKey, sText, "FOLDER")
'
' Record parent ID
'
lList = lList + 1 ReDim Preserve sData(1 To lList)
sData(lList) = "C" & sParent
'nNode.Tag = "C" & sParent
rsSections.MoveNext
Loop End With
'
' Here's where we rebuild the structure of the nodes
'
lList = 0
For Each nNode In tvProduct.Nodes
lList = lList + 1
'sParent = nNode.Tag
sParent = sData(lList)
If Len(sParent) > 0 Then
If sParent = "C0" Then
sParent = "ROOT"
End If
Set nNode.Parent = tvProduct.Nodes(sParent)
End If
Next nNode
'
' Now setup the images for each node in the treeview & set each node to
' be sorted if it has children
'
For Each nNode In tvProduct.Nodes
If nNode.Children = 0 Then
nNode.Image = "CHILD"
Else
nNode.Sorted = True
End If
Next nNode rsSections.Close
Set rsSections = Nothing '
' Expand the Root Node
'
tvProduct.Nodes("ROOT").Sorted = True
tvProduct.Nodes("ROOT").Expanded = True TreeRedraw tvProduct.hWnd, TrueExit SubvbErrorHandler: TreeRedraw tvProduct.hWnd, True MsgBox Err.Number & " " & Err.Description & " " & Err.Source & " frmProduct::pvFillTree", , App.ProductNameEnd SubPrivate Sub TreeRedraw(ByVal lHwnd As Long, ByVal bRedraw As Boolean)'
' Utility Routine for TreeRedraw on/off
' SendMessageLong lHwnd, WM_SETREDRAW, bRedraw, 0End Sub
Private Sub BoldTreeNode(nNode As Node)
On Error GoTo vbErrorHandlerDim TVI As TVITEM
Dim lRet As Long
Dim hItemTV As Long
Dim lHwnd As Long Set tvProduct.SelectedItem = nNode lHwnd = tvProduct.hWnd
hItemTV = SendMessageLong(lHwnd, TVM_GETNEXTITEM, TVGN_CARET, 0&) If hItemTV > 0 Then
With TVI
.hItem = hItemTV
.mask = TVIF_STATE
.stateMask = TVIS_BOLD
lRet = SendMessageAny(lHwnd, TVM_GETITEM, 0&, TVI)
.State = TVIS_BOLD
End With
lRet = SendMessageAny(lHwnd, TVM_SETITEM, 0&, TVI)
End IfExit SubvbErrorHandler:
MsgBox Err.Number & " " & Err.Description & " " & Err.Source, , "frmProduct::BoldTreeNode"End Sub