Как отправить выбранное значение treeview в текстовые поля
I have a access database with two tables namely Tblreqs and Tbllib, I used Tblreqs to populate into treeview, i want to use the selected node to fill textboxes with data from Tbllib. Here are the codes have tried so far
Что я уже пробовал:
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 Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterSelect Dim cn As OleDbConnection Dim wybrany As String wybrany = e.Node.Text cn = TblreqsTableAdapter.Connection Dim cmd As New OleDbCommand Dim dat As OleDbDataReader Dim querry As String = "select Refno, Group, Details, Qty, Rate, Total, Unit from tbllib where (detail) = '" + wybrany + "'" cmd = New OleDbCommand(querry, cn) dat = cmd.ExecuteReader While dat.Read() RefnoTextBox.Text = dat.Item(0).ToString GroupTextBox.Text = dat.Item(1).ToString DetailsTextBox.Text = dat.Item(2).ToString QtyTextBox.Text = dat.Item(3).ToString RateTextBox.Text = dat.Item(4).ToString TotalTextBox.Text = dat.Item(5).ToString UnitTextBox.Text = dat.Item(6).ToString End While End Sub End Class