Relational TreeView : TreeView « GUI « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » GUI » TreeViewScreenshots 
Relational TreeView
  

Imports System.Data.SqlClient
Imports System.Windows.Forms

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Relation
    Inherits System.Windows.Forms.Form

    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.SplitContainer1 = New System.Windows.Forms.SplitContainer
        Me.treeDB = New System.Windows.Forms.TreeView
        Me.txtInfo = New System.Windows.Forms.TextBox
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.cmdClear = New System.Windows.Forms.Button
        Me.cmdFill = New System.Windows.Forms.Button
        Me.SplitContainer1.Panel1.SuspendLayout()
        Me.SplitContainer1.Panel2.SuspendLayout()
        Me.SplitContainer1.SuspendLayout()
        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'SplitContainer1
        '
        Me.SplitContainer1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.SplitContainer1.Font = New System.Drawing.Font("Tahoma"8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.SplitContainer1.Location = New System.Drawing.Point(55)
        Me.SplitContainer1.Name = "SplitContainer1"
        '
        'SplitContainer1.Panel1
        '
        Me.SplitContainer1.Panel1.Controls.Add(Me.treeDB)
        '
        'SplitContainer1.Panel2
        '
        Me.SplitContainer1.Panel2.Controls.Add(Me.txtInfo)
        Me.SplitContainer1.Size = New System.Drawing.Size(460235)
        Me.SplitContainer1.SplitterDistance = 152
        Me.SplitContainer1.TabIndex = 8
        '
        'treeDB
        '
        Me.treeDB.Dock = System.Windows.Forms.DockStyle.Fill
        Me.treeDB.Font = New System.Drawing.Font("Tahoma"8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.treeDB.Location = New System.Drawing.Point(00)
        Me.treeDB.Name = "treeDB"
        Me.treeDB.Size = New System.Drawing.Size(152235)
        Me.treeDB.TabIndex = 6
        '
        'txtInfo
        '
        Me.txtInfo.Dock = System.Windows.Forms.DockStyle.Fill
        Me.txtInfo.Font = New System.Drawing.Font("Tahoma"8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtInfo.Location = New System.Drawing.Point(00)
        Me.txtInfo.Multiline = True
        Me.txtInfo.Name = "txtInfo"
        Me.txtInfo.ReadOnly = True
        Me.txtInfo.Size = New System.Drawing.Size(304235)
        Me.txtInfo.TabIndex = 8
        '
        'Panel1
        '
        Me.Panel1.Controls.Add(Me.cmdClear)
        Me.Panel1.Controls.Add(Me.cmdFill)
        Me.Panel1.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.Panel1.Font = New System.Drawing.Font("Tahoma"8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Panel1.Location = New System.Drawing.Point(5240)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(46028)
        Me.Panel1.TabIndex = 7
        '
        'cmdClear
        '
        Me.cmdClear.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.cmdClear.Location = New System.Drawing.Point(3864)
        Me.cmdClear.Name = "cmdClear"
        Me.cmdClear.Size = New System.Drawing.Size(7224)
        Me.cmdClear.TabIndex = 4
        Me.cmdClear.Text = "Clear"
        '
        Me.cmdFill.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.cmdFill.Location = New System.Drawing.Point(44)
        Me.cmdFill.Name = "cmdFill"
        Me.cmdFill.Size = New System.Drawing.Size(7224)
        Me.cmdFill.TabIndex = 3
        Me.cmdFill.Text = "Fill"
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(470273)
        Me.Controls.Add(Me.SplitContainer1)
        Me.Controls.Add(Me.Panel1)
        Me.Name = "Relation"
        Me.Padding = New System.Windows.Forms.Padding(5)
        Me.Text = "Relation"
        Me.SplitContainer1.Panel1.ResumeLayout(False)
        Me.SplitContainer1.Panel2.ResumeLayout(False)
        Me.SplitContainer1.Panel2.PerformLayout()
        Me.SplitContainer1.ResumeLayout(False)
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents SplitContainer1 As System.Windows.Forms.SplitContainer
    Friend WithEvents treeDB As System.Windows.Forms.TreeView
    Friend WithEvents txtInfo As System.Windows.Forms.TextBox
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents cmdClear As System.Windows.Forms.Button
    Friend WithEvents cmdFill As System.Windows.Forms.Button

    Private Sub cmdFill_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles cmdFill.Click
        Dim Connect As String = "Data Source=localhost;Integrated Security=True;Initial Catalog=Northwind;"
        Dim con As New SqlConnection(Connect)

        Dim SQL As String = "SELECT * FROM Orders WHERE OrderDate < '2000/01/01' AND OrderDate > '1987/01/01'"
        Dim cmd As New SqlCommand(SQL, con)

        Dim adapter As New SqlDataAdapter(cmd)
        Dim dsNorthwind As New DataSet()

        con.Open()

        adapter.Fill(dsNorthwind, "Orders")
        cmd.CommandText = "SELECT * FROM Customers"
        adapter.Fill(dsNorthwind, "Customers")

        cmd.CommandText = "SELECT * FROM Employees"
        adapter.Fill(dsNorthwind, "Employees")

        con.Close()
        Dim relCustomersOrders As New DataRelation("CustomersOrders", _
         dsNorthwind.Tables("Customers").Columns("CustomerID"), _
         dsNorthwind.Tables("Orders").Columns("CustomerID"))

        dsNorthwind.Relations.Add(relCustomersOrders)

        Dim nodeParent, nodeChild As TreeNode
        Dim rowParent, rowChild As DataRow
        For Each rowParent In dsNorthwind.Tables("Customers").Rows
            nodeParent = treeDB.Nodes.Add(rowParent("CompanyName"))
            nodeParent.Tag = rowParent
            For Each rowChild In rowParent.GetChildRows(relCustomersOrders)
                nodeChild = nodeParent.Nodes.Add(rowChild("OrderID"))
                nodeChild.Tag = rowChild
            Next
        Next
    End Sub
    Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles cmdClear.Click
        treeDB.Nodes.Clear()
    End Sub

    Private Sub treeDB_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgsHandles treeDB.AfterSelect
        txtInfo.Text = ""
        Dim row As DataRow = CType(e.Node.Tag, DataRow)
        Dim Field As Object
        For Each Field In row.ItemArray
            txtInfo.Text &= Field.ToString & vbNewLine
        Next

    End Sub
End Class

   
    
  
Related examples in the same category
1.Tree DemoTree Demo
2.Add Mouse Click event to a TreeView: display full pathAdd Mouse Click event to a TreeView: display full path
3.Add Node and Leap to a TreeViewAdd Node and Leap to a TreeView
4.Custom Tree ViewCustom Tree View
5.Use Tree View to display directoryUse Tree View to display directory
6.Using a TreeView to display the directory structureUsing a TreeView to display the directory structure
7.TreeView: Resource Browser
8.Directory Tree
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.