Results 1 to 3 of 3

Thread: Building TreeView from Database Example

  1. #1

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610

    Building TreeView from Database Example

    Does anyone know a good example of creating a TreeView from a database? I have been able to get part of it done but I was not sure if I was heading in the right direction with this project. My next step is when I click on a node in the tree is to get the info from the database that is related to that node.

    Thanks for the advice
    This space for rent...

  2. #2
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    There's one that comes with the MSDN library, i'll attach it for you. The database it uses is 3MB though, I could upload it or e-mail if you wanted.
    -adehh
    Attached Files Attached Files

  3. #3

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    Thanks for the code adzzzz I will take a look at it,

    Here is what I came up with so far...

    Code:
        Private Sub tvCodeLibrary_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvCodeLibrary.AfterSelect
    
            Dim NameID As Long
            Dim MyAdapter As New OleDbDataAdapter
            Dim MyDataset As New DataSet
            Dim MyCommand As New OleDbCommand
            Dim MyRow As DataRow
    
            Me.txtDescription.Text = ""
            Me.rtbCodeWindow.Text = ""
            Me.txtNote.Text = ""
    
            NameID = Me.tvCodeLibrary.SelectedNode.Tag
    
            MyCommand = New OleDbCommand("SELECT Description, Code, Note from Code where ID = " & NameID, MyConnection)
            MyAdapter = New OleDbDataAdapter(MyCommand)
            MyAdapter.Fill(MyDataset, "Code")
    
            For Each MyRow In MyDataset.Tables("Code").Rows
                If IsDBNull(MyRow("Description")) <> True Then Me.txtDescription.Text = MyRow("Description")
                If IsDBNull(MyRow("Code")) <> True Then Me.rtbCodeWindow.Text = MyRow("Code")
                If IsDBNull(MyRow("Note")) <> True Then Me.txtNote.Text = MyRow("Note")
            Next MyRow
    
            MyDataset.Tables("Code").Clear()
    
        End Sub
    This space for rent...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width