VB.NET - Treeview to Textbox vb - Asked By Opeyemi Ige on 16-Sep-20 11:22 AM

I have a database with two tables namely Table A and Table B, I used Table A to populate into treeview, i want to use the selected node to fill textboxes with data from Table B.


Imports System.Data.OleDb
Public Class Form1

    Private Sub TblreqsBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs)
        Me.Validate()
        Me.TblreqsBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.CopycopyDataSet)

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'CopycopyDataSet.tbllib' table. You can move, or remove it, as needed.
        Me.TbllibTableAdapter.Fill(Me.CopycopyDataSet.tbllib)
        'TODO: This line of code loads data into the 'CopycopyDataSet.tbllib' table. You can move, or remove it, as needed.
        Me.TbllibTableAdapter.Fill(Me.CopycopyDataSet.tbllib)
        'TODO: This line of code loads data into the 'CopycopyDataSet.tbllib' table. You can move, or remove it, as needed.
        Me.TbllibTableAdapter.Fill(Me.CopycopyDataSet.tbllib)
        'TODO: This line of code loads data into the 'CopycopyDataSet.tblreqs' table. You can move, or remove it, as needed.
        Me.TblreqsTableAdapter.Fill(Me.CopycopyDataSet.tblreqs)

        GroupTextBox.Text = " "
        DetailsTextBox.Text = " "
        RefnoTextBox.Text = " "
        QtyTextBox.Text = " "
        RateTextBox.Text = " "
        UnitTextBox.Text = " "
        TotalTextBox.Text = " "

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TblreqsTableAdapter.Connection.Open()
        TreeView1.Nodes.Clear()
        FillTree("1", "Library", Nothing)
        TblreqsTableAdapter.Connection.Close()
    End Sub

    Public Sub FillTree(ByVal Key As String, ByVal Txt As String, ByVal N As TreeNode)
        Dim cn As OleDbConnection
        Dim cmd As OleDbCommand
        Dim NN As TreeNode
        If N Is Nothing Then
            NN = TreeView1.Nodes.Add(Key, Txt)
        Else
            NN = N.Nodes.Add(Key, Txt)
        End If
        cn = TblreqsTableAdapter.Connection
        cmd = New OleDbCommand("select * from tblreqs where idparent='" & Key & "'", cn)
        Dim dr = cmd.ExecuteReader
        Do While dr.Read()
            FillTree(dr("id"), dr("detail"), NN)
        Loop
        dr.Close()
        cmd.Dispose()
    End Sub

End Class