Using Collection to populate TreeView...
From: RPK (RPK_at_discussions.microsoft.com)
Date: 01/26/05
- Next message: Shawn G.: "VB.NET EM_STREAMOUT Code"
- Previous message: Gil Gerald Gonong: "Re: Can anyone help me??"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 25 Jan 2005 21:29:01 -0800
I want to display a Tree with City as Parent Node and Customers of that city
as Child to that node.
Example:
+CITY1
|...ABC
|...XYZ
+CITY2
|...DEF
|...PHQ
I wrote following code but it displays error at line "sCity =
CityColl.Item(CStr(i))".
Error: "Object is no longer valid".
I am using a collection which stores names of cities extracted by SQL and
then this
collection to populate TREE. The Collection is defined globally in the Form
and is filled with Cities as the
Form Loads.
Help me on how to arrange as above.
[code] Private Sub addtree()
Dim TotCity, TotRec, i, j
Dim SearchQuery As String
Dim sCity
Dim rsSelectCity As ADODB.Recordset
'Count City Collection Items
TotCity = CityColl.Count
'Open recordset
Set rsSelectCity = New ADODB.Recordset
If rsSelectCity.State = adStateClosed Then
rsSelectCity.Open "Select * from customer", conn, adOpenKeyset,
adLockReadOnly
End If
TotRec = rsSelectCity.RecordCount
'Populate Tree
For i = 1 To TotCity
sCity = CityColl.Item(CStr(i))
TreeView1.Nodes.Add , , "c" & i, UCase(sCity)
'Update Query String Instantly
SearchQuery = "Select CustID, CustName, Location From customer Where
City = '" & strCity & "'"
For j = 1 To TotRec
TreeView1.Nodes.Add "c" & i, , "c" & j, UCase(sCity)
Next j
Next
End Sub [/code]
- Next message: Shawn G.: "VB.NET EM_STREAMOUT Code"
- Previous message: Gil Gerald Gonong: "Re: Can anyone help me??"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|