Dear All,

I have few question regarding using Treeview in my project. The screen of my project is been attched.

I can populate the data from database in treeview using following code:

Imports System.Data.SqlClient
Public Class Tree

    Private Sub Tree_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim dsTest As DataSet
        Dim cnTest As New SqlClient.SqlConnection("DATA SOURCE=myPC\DBserver;USER ID=sa;PASSWORD=udo5673;INITIAL CATALOG=ZINDAA;")
        Dim daCountry As New SqlClient.SqlDataAdapter("SELECT CsCountryCode,CsCountryName from hrCountrySetup", cnTest)
        dsTest = New DataSet()
        daCountry.Fill(dsTest, "dtCountry")

        Dim parentrow As DataRow
        Dim parenttable As DataTable
        parenttable = dsTest.Tables("dtCountry")
        For Each parentrow In parenttable.Rows
            Dim parentnode As New TreeNode
            parentnode = New TreeNode(parentrow.Item(0) & " - " & parentrow.Item(1))
        Next parentrow
    End Sub
End Class

now with my treeview, i want to fill my texbox1,textbox2 with the value of treeview node when user selects the treeview node.

I could get idea on how to. CAN ANYONE HELP ME?

Recommended Answers

All 2 Replies

Try this :

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
    Dim temp() As String = Split(TreeView1.SelectedNode.Text, "-")
    TextBox1.Text = Trim(temp(0).ToString)
    TextBox2.Text = Trim(temp(1).ToString)
End Sub

In the AfterSelect event handler of the treeview you can do

Dim text() As String = TreeView1.SelectedNode.Text.Split("-")

Then your first textbox is Trim(text(0)) and the second textbox is Trim(text(1))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.