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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview going out of bounds !!!

Status
Not open for further replies.

MattBegg

Programmer
Jan 19, 2001
42
0
0
CA
I am trying to build a treeview in my application based on a database.

The treeview I am looking to build is going out of bounds

The control is built from 4 tables
1: country (4 records)
2: county (106 records)
3: town (20018 records)
4: solicitors (54 records)

I have pasted the code below, I have gone wrong somewhere I am sure.

Private Sub treeview()

' Declare recordsets for each table

Dim rsCountry As Recordset
Dim rsCounty As Recordset
Dim rsTown As Recordset
Dim rsSolicitors As Recordset

' Set each recordset
Set rsCountry = mDBQuotes.OpenRecordset("tblCountry", dbOpenDynaset)
Set rsCounty = mDBQuotes.OpenRecordset("tblCounty", dbOpenDynaset)
Set rsTown = mDBQuotes.OpenRecordset("tblTowns", dbOpenDynaset)
Set rsSolicitors = mDBQuotes.OpenRecordset("tblSolicitors", dbOpenDynaset)

rsCountry.MoveFirst

Dim intIndex As Integer, intIndex2 As Integer, intIndex3 As Integer

Do Until rsCountry.EOF
Set mNode = TreeView1.Nodes.Add(1, tvwChild)
mNode.Text = rsCountry!Country
mNode.Tag = "Country"
mNode.key = rsCountry!countriesid & "country"
intIndex = mNode.Index
Do Until rsCounty.EOF
If rsCountry!countriesid = rsCounty!countriesid Then
Set mNode = TreeView1.Nodes.Add(intIndex, tvwChild)
mNode.Text = rsCounty!County
mNode.key = rsCounty!countiesid & "county"
mNode.Tag = "County"
mNode.Image = 2
intIndex2 = mNode.Index
End If
Do Until rsTown.EOF
If rsCounty!countiesid = rsTown!countiesid Then
Set mNode = TreeView1.Nodes.Add(intIndex2, tvwChild)
mNode.Text = rsTown!town
mNode.key = rsTown!townsid & "town"
mNode.Tag = "Town"
mNode.Image = 4
intIndex3 = mNode.Index
End If
Do Until rsSolicitors.EOF
If rsTown!townsid = rsSolicitors!townsid Then
Set mNode = TreeView1.Nodes.Add(intIndex3, tvwChild)
mNode.Text = rsSolicitors!CompanyName
mNode.key = rsSolicitors!solicitorsid & "solicitor"
mNode.Tag = "Solicitors"
mNode.Image = 6
End If
rsSolicitors.MoveNext
Loop
rsSolicitors.MoveFirst
rsTown.MoveNext
Loop
rsTown.MoveFirst
rsCounty.MoveNext
Loop
rsCounty.MoveFirst
rsCountry.MoveNext
Loop
End Sub

Can anybody give it a look as a fresh pair of eyes ??

Any help would be grateful

Regards

Matt

matt@begg-uk.co.uk
 
Hi Matt.

When the code breaks, use the immediate window (with debug.print) to show Treeview.nodes.count to see how many
nodes it let you create. If it is a power of 2 +/- 1 then you are probably reaching the limit of the control.
The user may have to select country (and county?) from
a combo box first, so that you don't have too many nodes...

Perhaps the data structure needs to be revamped, is the database going to grow substantially?
Perhaps you could only show towns where a solicitor is
listed etc?

Gzep, SOF.
 
Matt,
Gzep's right: that's getting to be one tall tree that might be hard to read...

Please try switching to Longs, as Integers top out at 32,767. Just might fly. Gord
ghubbell@total.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top