I hope there is somebody out there who can help
I want to load a treeview in vb.net
Globe
Country
City
Hotel
I am using the tag property and dummy node to deceive vb that there is a node and then in the beforeExpand
event
process the node that it is clicked.
WHY ISN'T THE DUMMYNODE LOADED AND SHOWING THE + SIGN UNDER EACH COUNTRYnODE?
I load Globe (root node ) and country but I cannot load
City.this is the code:
'//declare the nodes
Private CountryNode As TreeNode = New TreeNode()
Private CityNode As TreeNode = New TreeNode()
Private DummyNode As TreeNode = New TreeNode()
Private Sub LoadCountry()'//when form loads
Dim GlobeNode As TreeNode = New TreeNode()
Dim CountryReader As SqlDataReader
Dim conn As SqlConnection = _
New SqlConnectionconnectionString)
conn.Open()
Try
CountryReader = SqlHelper.ExecuteReader _(conn,"Country_Read_all"
With tvwContracts.Nodes
.Clear()
GlobeNode = tvwContracts.Nodes.Add(0)
GlobeNode.Text = ("Globe"
GlobeNode.Tag = "x_"
Do While CountryReader.Read()
CountryNode.Text = _
'//load countryName
(CountryReader.Item("CountryName")
'//add countryName to GlobeNode(RootNode)
GlobeNode.Nodes.Add(CountryNode.Text)
'//add a tag so that I can identify the node
CountryNode.Tag = _
mcCountryKey & CountryReader.Item("CountryID"
'//add a CitydummyNode to the CountryNode so that I can
'//have a + sign and then process this in the BeforeExpand event
countryNode.nodes.add(DummyNode)
Loop
End With
End Sub
'///////////////
Private Sub tvwContracts_BeforeExpand(ByVal sender As Object, ByVal e
As System.Windows.Forms.TreeViewCancelEventArgs) Handles
tvwContracts.BeforeExpand
'//the following is a substitute for the left function in vb6
Dim strNdTag As String, strNdTagStripped As String
strNdTag = e.Node.Tag
strNdTagStripped = strNdTag.Substring(0, 2)
'check if there are children in the node
if e.node.nodes.count > 0 then
If strNdTagStripped = mcDummyKey Then
Select Case strNdTagStripped
Case mcCityKey
LoadCity(e.Node.Tag)
Case mcHotelKey
End Select
End If
end if
End Sub
I want to load a treeview in vb.net
Globe
Country
City
Hotel
I am using the tag property and dummy node to deceive vb that there is a node and then in the beforeExpand
event
process the node that it is clicked.
WHY ISN'T THE DUMMYNODE LOADED AND SHOWING THE + SIGN UNDER EACH COUNTRYnODE?
I load Globe (root node ) and country but I cannot load
City.this is the code:
'//declare the nodes
Private CountryNode As TreeNode = New TreeNode()
Private CityNode As TreeNode = New TreeNode()
Private DummyNode As TreeNode = New TreeNode()
Private Sub LoadCountry()'//when form loads
Dim GlobeNode As TreeNode = New TreeNode()
Dim CountryReader As SqlDataReader
Dim conn As SqlConnection = _
New SqlConnectionconnectionString)
conn.Open()
Try
CountryReader = SqlHelper.ExecuteReader _(conn,"Country_Read_all"
With tvwContracts.Nodes
.Clear()
GlobeNode = tvwContracts.Nodes.Add(0)
GlobeNode.Text = ("Globe"
GlobeNode.Tag = "x_"
Do While CountryReader.Read()
CountryNode.Text = _
'//load countryName
(CountryReader.Item("CountryName")
'//add countryName to GlobeNode(RootNode)
GlobeNode.Nodes.Add(CountryNode.Text)
'//add a tag so that I can identify the node
CountryNode.Tag = _
mcCountryKey & CountryReader.Item("CountryID"
'//add a CitydummyNode to the CountryNode so that I can
'//have a + sign and then process this in the BeforeExpand event
countryNode.nodes.add(DummyNode)
Loop
End With
End Sub
'///////////////
Private Sub tvwContracts_BeforeExpand(ByVal sender As Object, ByVal e
As System.Windows.Forms.TreeViewCancelEventArgs) Handles
tvwContracts.BeforeExpand
'//the following is a substitute for the left function in vb6
Dim strNdTag As String, strNdTagStripped As String
strNdTag = e.Node.Tag
strNdTagStripped = strNdTag.Substring(0, 2)
'check if there are children in the node
if e.node.nodes.count > 0 then
If strNdTagStripped = mcDummyKey Then
Select Case strNdTagStripped
Case mcCityKey
LoadCity(e.Node.Tag)
Case mcHotelKey
End Select
End If
end if
End Sub