Hi all,
Really jammed, hope you can help.
I have 1 SQL table, Job.
Lets say I have 3 records:
Job_ID, Job_Number, TLN_NO
1 J1000
2 J1001 1
3 J1002 2
I have a treeview that I want to populate automatically. I start by populating that treeview with a root node, in this case it would be J1000.
I then run the following code, but it only goes to the 1st level, what I want is all of the levels, no matter how many exist. There could be 12 2nd Levels, and of them only 4 have a 3rd. Heres my code. I have tried looping it but it never budges off the top level node, or adds any 3rd levels. So the best I get is the root + 1 level...
Any help much appreicated...
For Each Node In tvStructure.Nodes
Dim mySelectedNode As TreeNode
tvStructure.SelectedNode = Node
mySelectedNode = Node
Dim strLoop As String
strLoop = "SELECT Job.ID, Job_Number FROM Job WHERE TLJ_No = '" & mySelectedNode.Text & "'"
Dim ConnLoop As New SqlClient.SqlConnection(My.Settings.Fusion_AWS_DataConnectionString)
Dim CommLoop As New SqlClient.SqlCommand(strLoop, ConnLoop)
Dim DrLoop As SqlClient.SqlDataReader
ConnLoop.Open()
DrLoop = CommLoop.ExecuteReader
If DrLoop.HasRows Then
While DrLoop.Read
Dim NewChildNode As New TreeNode
NewChildNode.Text = DrLoop("Job_Number")
tvStructure.SelectedNode.Nodes.Add(NewChildNode)
End While
End If
tvStructure.Refresh()
Next
So at the moment with the above I get a treeview with J1000 and then a child node of J1001. I was hoping I would have got a 3rd child node from J1001 saying J1002..
Thanks again,
Chris.
Really jammed, hope you can help.
I have 1 SQL table, Job.
Lets say I have 3 records:
Job_ID, Job_Number, TLN_NO
1 J1000
2 J1001 1
3 J1002 2
I have a treeview that I want to populate automatically. I start by populating that treeview with a root node, in this case it would be J1000.
I then run the following code, but it only goes to the 1st level, what I want is all of the levels, no matter how many exist. There could be 12 2nd Levels, and of them only 4 have a 3rd. Heres my code. I have tried looping it but it never budges off the top level node, or adds any 3rd levels. So the best I get is the root + 1 level...
Any help much appreicated...
For Each Node In tvStructure.Nodes
Dim mySelectedNode As TreeNode
tvStructure.SelectedNode = Node
mySelectedNode = Node
Dim strLoop As String
strLoop = "SELECT Job.ID, Job_Number FROM Job WHERE TLJ_No = '" & mySelectedNode.Text & "'"
Dim ConnLoop As New SqlClient.SqlConnection(My.Settings.Fusion_AWS_DataConnectionString)
Dim CommLoop As New SqlClient.SqlCommand(strLoop, ConnLoop)
Dim DrLoop As SqlClient.SqlDataReader
ConnLoop.Open()
DrLoop = CommLoop.ExecuteReader
If DrLoop.HasRows Then
While DrLoop.Read
Dim NewChildNode As New TreeNode
NewChildNode.Text = DrLoop("Job_Number")
tvStructure.SelectedNode.Nodes.Add(NewChildNode)
End While
End If
tvStructure.Refresh()
Next
So at the moment with the above I get a treeview with J1000 and then a child node of J1001. I was hoping I would have got a 3rd child node from J1001 saying J1002..
Thanks again,
Chris.