How to Bind Selected Tree Node to form controls

tashiduks

Member
Joined
Apr 19, 2010
Messages
22
Programming Experience
Beginner
Hi Everyone,

I have following code which populates the data from database to treeview node.

VB.NET:
Private Sub FormLoad()
        Dim cnTest As New SqlClient.SqlConnection("DATA SOURCE=tashi\dbtestsrv;USER ID=sa;PASSWORD=s@1234;INITIAL CATALOG=BDFCLHR;")
        'Dim daCountry As New SqlClient.SqlDataAdapter("SELECT CsCountryCode,CsCountryName from hrCountrySetup", cnTest)
        Dim strSelectQry As String
        strSelectQry = "SELECT [gpsGrade] ,[gpsIntGrade] ,[gpsMinPay] ,[gpsIncrement] ,[gpsMaxPay] ,[gpsGISGroup] ,[gpsGISCont] ,[gpsSWSCont] ,[gpsSWSPercentageYN] ,[gpsRetirementAge] FROM [BDFCLHR].[dbo].[hrGradePayScale]"
        Dim daCountry As New SqlClient.SqlDataAdapter(strSelectQry, cnTest)
        dsTest = New DataSet()
        cnTest.Open()
        daCountry.Fill(dsTest, "dtCountry")
        cnTest.Close()
        TreeView1.Nodes.Clear()
        'Dim parentrow As DataRow
        'Dim parenttable As DataTable
        Dim parentnode As New TreeNode
        Dim childNode As TreeNode
        parentnode = New TreeNode("Grade")
        TreeView1.Nodes.Add(parentnode)

        ParentTable = dsTest.Tables("dtCountry")
        For Each Me.ParentROW In ParentTable.Rows
            childNode = New TreeNode(ParentROW.Item(1) & " - " & ParentROW.Item(2) & " - " & ParentROW.Item(3) & " - " & ParentROW.Item(4))
            parentnode.Nodes.Add(childNode)

            'TextBox1.Text = ParentROW.Item(0)
            'TextBox2.Text = ParentROW.Item(1)
        Next ParentROW
        TextBox1.Enabled = False
        TextBox2.Enabled = False
    End Sub

I have a form with following form controls which should fill the value of selected node to controls:
gpsGrade.text
gpsIntGrade.text
gpsMinPay.text
gpsIncrement.text
gpsMaxPay.text
gpsGISGroup.text
gpsGISCont.text
gpsSWSCont.text
gpsSWSPercentageYN.checkstate
gpsRetirementAge.text

I am using VB languagqe in VB.NET 2010 with SQL SERVER 2008. So can anyone tell me how fill the selected node value to the respective form controls when user selects the treenode.
 
I would bind your DataTable to a BindingSource and bind that to your TextBoxes. Each time you create a TreeNode for a DataRow, assign the row to the node's Tag. When the user selects a node, get the row from its Tag and assign that to the Current property of the BindingSource. The rest is done for you.
 
Hi,

Thanks for the response for my question. I would appreciate if you can tell me how to do it (Code), since i dont have any idea regarding this. I have seek help from many source but failed to get the correct answer.

I would appreciate if you can give me the code so that i can make it up.

Thanks
 
Yes, I understand your views. Well i am the self learner person and till now i have been doing the codding by myself by seeking help from the NET using google. But this time its very difficult to get the proper solution for my problem and i am requesting you to help me by providing the basic code so that i can get the idea how to do.

Thanks
 
Back
Top