在VB.NET中,可以使用TreeView控件來實現貨品的樹狀結構分類。以下是一個簡單的示例:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' 加載貨品數據并生成樹狀結構
Dim rootCategory As New TreeNode("所有貨品")
TreeView1.Nodes.Add(rootCategory)
' 假設有以下貨品數據
Dim categories As New List(Of String) From {"電子產品", "服裝", "食品"}
Dim electronicProducts As New List(Of String) From {"手機", "電視", "電腦"}
Dim clothing As New List(Of String) From {"襯衫", "褲子", "鞋子"}
Dim food As New List(Of String) From {"牛奶", "面包", "水果"}
For Each category As String In categories
Dim categoryNode As New TreeNode(category)
rootCategory.Nodes.Add(categoryNode)
Select Case category
Case "電子產品"
For Each product As String In electronicProducts
categoryNode.Nodes.Add(product)
Next
Case "服裝"
For Each product As String In clothing
categoryNode.Nodes.Add(product)
Next
Case "食品"
For Each product As String In food
categoryNode.Nodes.Add(product)
Next
End Select
Next
End Sub
以上代碼在TreeView控件中生成了一個樹狀結構,該結構包含一個根節點“所有貨品”,以及三個子節點“電子產品”、“服裝”和“食品”,每個子節點下面又有若干個貨品節點。
你可以根據實際情況修改以上示例代碼,加載自己的貨品數據,并根據需求來構建樹狀結構。