Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to populate a treeview control

Status
Not open for further replies.

talenx

Programmer
Aug 7, 2001
157
US
Hello, I know that this question has been asked numerous times but I fail to see the relation between populating a treeview control with normalized data in two or more tables.
I seen some cases where the tree view node is populated by a list control and I have seen it created manually where each node is giving a string name.

I think what I will need to do should fairly simple...
The treeview control will only show three node options.

Treeview Layout
-------------------------------------------------------
REGION---primary node
|
MARKET----1st Child Node
|
COUNTY----2nd Child Node


The Geo Tables layout:
------------------------------------------------
REGION [RegionID] [RegionName]

MARKET [RegionID] [MarketID] [MarketName]

COUNTY [RegionID] [MarketID] [CountyID] [CountyName]

Does anybody know I may begin to populate the treeview control with the desired hierarchy?

Thank you very much!!
 
it depends on how you want to load it

I prefer to load the next level when I click on a node. it loads faster, but here is loading them all on open

in the forms onload event this code should be close to what you need. I typeed it on the fly so will need serious debugging

Dim rstregion as recordset,rstmarket as recordset
db as currentdb, rstcounty as recordset
'load parentnodes
set db= currentdb
set rstregion = db.openrecordset("region")
do until rst.eof
me.treeview1.nodes.add ,,"r" & rstregion!regionID,rstregion!regionname
rstregion.movenext
loop
rstregion.close
'load market
set rstmarket = db.openrecordset("market")
do until rstmarket.eof
me.treeview1.nodes.add rstmarket!regionid,tvwchild,"M" & rstmarket!marketid,rstmarket.marketname
rstmarket.movenext
loop
rstmarket.close
'load county
set rstcount = db.openrecordset("county")
do until rstcounty.eof
me.treeview1.nodes.add rstcounty!marketid,tvwchild,"C" & rstcounty!countyid,rstcounty!countyname
rstcounty.movenext
loop
rstcounty.close
set rstcounty = nothing
set rstmarket = nothing
set rstregion = nothing
set db = nothing
end sub

hope this gets you started good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top