Option Strict Off
Option Explicit On
Imports NorthwindDatabase
Friend Class frmProducts
Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
If Disposing Then
If Not components Is Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(Disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
Public ToolTip1 As System.Windows.Forms.ToolTip
Public WithEvents cmdClose As System.Windows.Forms.Button
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents tvwCategories As System.Windows.Forms.TreeView
Friend WithEvents lvwProducts As System.Windows.Forms.ListView
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnHeader4 As System.Windows.Forms.ColumnHeader
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.cmdClose = New System.Windows.Forms.Button
Me.tvwCategories = New System.Windows.Forms.TreeView
Me.lvwProducts = New System.Windows.Forms.ListView
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader3 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader4 = New System.Windows.Forms.ColumnHeader
Me.SuspendLayout()
'
'cmdClose
'
Me.cmdClose.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.cmdClose.BackColor = System.Drawing.SystemColors.Control
Me.cmdClose.Cursor = System.Windows.Forms.Cursors.Default
Me.cmdClose.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.cmdClose.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.cmdClose.ForeColor = System.Drawing.SystemColors.ControlText
Me.cmdClose.Location = New System.Drawing.Point(617, 412)
Me.cmdClose.Name = "cmdClose"
Me.cmdClose.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.cmdClose.Size = New System.Drawing.Size(89, 24)
Me.cmdClose.TabIndex = 2
Me.cmdClose.Text = "&Close"
'
'tvwCategories
'
Me.tvwCategories.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.tvwCategories.ImageIndex = -1
Me.tvwCategories.Location = New System.Drawing.Point(4, 4)
Me.tvwCategories.Name = "tvwCategories"
Me.tvwCategories.SelectedImageIndex = -1
Me.tvwCategories.Size = New System.Drawing.Size(220, 400)
Me.tvwCategories.TabIndex = 0
'
'lvwProducts
'
Me.lvwProducts.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.lvwProducts.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3, Me.ColumnHeader4})
Me.lvwProducts.Location = New System.Drawing.Point(228, 4)
Me.lvwProducts.Name = "lvwProducts"
Me.lvwProducts.Size = New System.Drawing.Size(477, 398)
Me.lvwProducts.TabIndex = 1
Me.lvwProducts.View = System.Windows.Forms.View.Details
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "Name"
Me.ColumnHeader1.Width = 120
'
'ColumnHeader2
'
Me.ColumnHeader2.Text = "Supplier"
Me.ColumnHeader2.Width = 120
'
'ColumnHeader3
'
Me.ColumnHeader3.Text = "Unit Price"
Me.ColumnHeader3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
Me.ColumnHeader3.Width = 70
'
'ColumnHeader4
'
Me.ColumnHeader4.Text = "Quantity Per Unit"
Me.ColumnHeader4.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
Me.ColumnHeader4.Width = 100
'
'frmProducts
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.Control
Me.CancelButton = Me.cmdClose
Me.ClientSize = New System.Drawing.Size(710, 447)
Me.Controls.Add(Me.lvwProducts)
Me.Controls.Add(Me.tvwCategories)
Me.Controls.Add(Me.cmdClose)
Me.Cursor = System.Windows.Forms.Cursors.Default
Me.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Location = New System.Drawing.Point(3, 29)
Me.MinimizeBox = False
Me.Name = "frmProducts"
Me.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.ShowInTaskbar = False
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
Me.Text = "Products"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub LoadCategories()
Dim objCategory As Category
Dim objRoot As TreeNode
With Me.tvwCategories.Nodes
objRoot = .Add("All")
For Each objCategory In NorthwindDB.Categories
objRoot.Nodes.Add(objCategory.Name)
Next
objRoot.Expand()
End With
End Sub
Private Sub LoadProducts(ByVal objProducts As Products)
Dim objProduct As Product
With Me.lvwProducts.Items
.Clear()
For Each objProduct In objProducts
With .Add(objProduct.Name)
.SubItems.Add(objProduct.Supplier.Name)
.SubItems.Add(objProduct.UnitPrice)
.SubItems.Add(objProduct.QuantityPerUnit)
End With
Next
End With
End Sub
Private Sub frmProducts_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
LoadCategories()
LoadProducts(NorthwindDB.Products)
End Sub
Private Sub cmdClose_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdClose.Click
Me.Close()
End Sub
Private Sub tvwCategories_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles tvwCategories.Click
End Sub
Private Sub tvwCategories_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwCategories.AfterSelect
If e.Node.Parent Is Nothing Then
LoadProducts(NorthwindDB.Products)
Else
LoadProducts(NorthwindDB.Categories(e.Node.Text).Products)
End If
End Sub
End Class