treeview - i'm on vb6
-
- PlatinumLounger
- Posts: 4470
- Joined: 26 Apr 2010, 17:36
treeview - i'm on vb6
Sorry Hans butI can't find your treeview example anymore...
in other case, i need:
big rooth ITALIA
- First rooth REG-REGIONE
- Second rooth PR-PROVINCIA
- Third rooth ISTAT-COMUNE
tks
in other case, i need:
big rooth ITALIA
- First rooth REG-REGIONE
- Second rooth PR-PROVINCIA
- Third rooth ISTAT-COMUNE
tks
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 79287
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4470
- Joined: 26 Apr 2010, 17:36
Re: treeview - i'm on vb6
FOUND!
but i need to join two filed by zona, regione, provincia, comune, similar:
Z-ZONA
REG-RGIONE
PR-PROVINCIA
ISTAT-COMUNE
1-NORD-OVEST
01-PIEMONTE
TO-TORINO
001272-TORINO
my code:
Code: Select all
Option Explicit
Private Sub Form_Load()
Dim nod As MSComctlLib.Node
Call APRI_CONN
arrLevels = Array("regione", "provincia", "comune", "istatext")
With Me.TreeView1
.LineStyle = tvwRootLines
.Style = tvwTreelinesPlusMinusText
.Nodes.Clear
Set nod = .Nodes.Add(Text:="Italia")
AddChildren nod, 0
End With
End Sub
Sub AddChildren(nod As MSComctlLib.Node, level As Long)
Dim rst As ADODB.Recordset
Dim fld As String
Dim sql As String
Dim chl As MSComctlLib.Node
fld = arrLevels(level)
sql = "SELECT DISTINCT [" & fld & "] FROM Comuni_ISTAT"
If level > 0 Then
sql = sql & " WHERE [" & arrLevels(level - 1) & "]='" & Replace(nod.Text, "'", "''") & "'"
End If
Set rst = New ADODB.Recordset
rst.Open Source:=sql, ActiveConnection:=CON, Options:=adCmdText
Do While Not rst.EOF
Set chl = Me.TreeView1.Nodes.Add(Relative:=nod, Relationship:=tvwChild, Text:=rst(fld))
If level < UBound(arrLevels) Then
AddChildren chl, level + 1
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub
-
- Administrator
- Posts: 79287
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: treeview - i'm on vb6
Does this work?
Code: Select all
Option Explicit
Private Sub Form_Load()
Dim nod As MSComctlLib.Node
Call APRI_CONN
arrLevels = Array("[Z] & '-' & [ZONA]", "[REG] & '-' & [REGIONE]", _
"[PR] & '-' & [PROVINCIA]", "[ISTATEXT] & '-' & [COMUNE]")
With Me.TreeView1
.LineStyle = tvwRootLines
.Style = tvwTreelinesPlusMinusText
.Nodes.Clear
Set nod = .Nodes.Add(Text:="Italia")
AddChildren nod, 0
End With
End Sub
Sub AddChildren(nod As MSComctlLib.Node, level As Long)
Dim rst As ADODB.Recordset
Dim fld As String
Dim sql As String
Dim chl As MSComctlLib.Node
fld = arrLevels(level)
sql = "SELECT DISTINCT " & fld & " FROM Comuni_ISTAT"
If level > 0 Then
sql = sql & " WHERE " & arrLevels(level - 1) & "='" & Replace(nod.Text, "'", "''") & "'"
End If
Set rst = New ADODB.Recordset
rst.Open Source:=sql, ActiveConnection:=CON, Options:=adCmdText
Do While Not rst.EOF
Set chl = Me.TreeView1.Nodes.Add(Relative:=nod, Relationship:=tvwChild, Text:=rst(fld))
If level < UBound(arrLevels) Then
AddChildren chl, level + 1
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4470
- Joined: 26 Apr 2010, 17:36
Re: treeview - i'm on vb6
HansV wrote: ↑19 Jun 2024, 09:51Does this work?
Code: Select all
Option Explicit Private Sub Form_Load() Dim nod As MSComctlLib.Node Call APRI_CONN arrLevels = Array("[Z] & '-' & [ZONA]", "[REG] & '-' & [REGIONE]", _ "[PR] & '-' & [PROVINCIA]", "[ISTATEXT] & '-' & [COMUNE]") With Me.TreeView1 .LineStyle = tvwRootLines .Style = tvwTreelinesPlusMinusText .Nodes.Clear Set nod = .Nodes.Add(Text:="Italia") AddChildren nod, 0 End With End Sub Sub AddChildren(nod As MSComctlLib.Node, level As Long) Dim rst As ADODB.Recordset Dim fld As String Dim sql As String Dim chl As MSComctlLib.Node fld = arrLevels(level) sql = "SELECT DISTINCT " & fld & " FROM Comuni_ISTAT" If level > 0 Then sql = sql & " WHERE " & arrLevels(level - 1) & "='" & Replace(nod.Text, "'", "''") & "'" End If Set rst = New ADODB.Recordset rst.Open Source:=sql, ActiveConnection:=CON, Options:=adCmdText Do While Not rst.EOF Set chl = Me.TreeView1.Nodes.Add(Relative:=nod, Relationship:=tvwChild, Text:=rst(fld)) If level < UBound(arrLevels) Then AddChildren chl, level + 1 End If rst.MoveNext Loop rst.Close Set rst = Nothing End Sub
on this line:
Set chl = Me.TreeView1.Nodes.Add(Relative:=nod, Relationship:=tvwChild, Text:=rst(fld))
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 79287
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: treeview - i'm on vb6
Is this better?
Code: Select all
Private Sub Form_Load()
Dim nod As MSComctlLib.Node
Call APRI_CONN
arrLevels = Array("[Z] & '-' & [ZONA]", "[REG] & '-' & [REGIONE]", _
"[PR] & '-' & [PROVINCIA]", "[ISTATEXT] & '-' & [COMUNE]")
With Me.TreeView1
.LineStyle = tvwRootLines
.Style = tvwTreelinesPlusMinusText
.Nodes.Clear
Set nod = .Nodes.Add(Text:="Italia")
AddChildren nod, 0
End With
End Sub
Sub AddChildren(nod As MSComctlLib.Node, level As Long)
Dim rst As ADODB.Recordset
Dim fld As String
Dim fldName As String
Dim sql As String
Dim chl As MSComctlLib.Node
fld = arrLevels(level)
fldName = "Level" & level
sql = "SELECT DISTINCT " & fld & " AS Level" & level & " FROM Comuni_ISTAT"
If level > 0 Then
sql = sql & " WHERE " & arrLevels(level - 1) & "='" & Replace(nod.Text, "'", "''") & "'"
End If
Set rst = New ADODB.Recordset
rst.Open Source:=sql, ActiveConnection:=CON, Options:=adCmdText
Do While Not rst.EOF
Set chl = Me.TreeView1.Nodes.Add(Relative:=nod, Relationship:=tvwChild, Text:=rst(fldName))
If level < UBound(arrLevels) Then
AddChildren chl, level + 1
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4470
- Joined: 26 Apr 2010, 17:36
Re: treeview - i'm on vb6
HansV wrote: ↑19 Jun 2024, 10:42Is this better?
Code: Select all
Private Sub Form_Load() Dim nod As MSComctlLib.Node Call APRI_CONN arrLevels = Array("[Z] & '-' & [ZONA]", "[REG] & '-' & [REGIONE]", _ "[PR] & '-' & [PROVINCIA]", "[ISTATEXT] & '-' & [COMUNE]") With Me.TreeView1 .LineStyle = tvwRootLines .Style = tvwTreelinesPlusMinusText .Nodes.Clear Set nod = .Nodes.Add(Text:="Italia") AddChildren nod, 0 End With End Sub Sub AddChildren(nod As MSComctlLib.Node, level As Long) Dim rst As ADODB.Recordset Dim fld As String Dim fldName As String Dim sql As String Dim chl As MSComctlLib.Node fld = arrLevels(level) fldName = "Level" & level sql = "SELECT DISTINCT " & fld & " AS Level" & level & " FROM Comuni_ISTAT" If level > 0 Then sql = sql & " WHERE " & arrLevels(level - 1) & "='" & Replace(nod.Text, "'", "''") & "'" End If Set rst = New ADODB.Recordset rst.Open Source:=sql, ActiveConnection:=CON, Options:=adCmdText Do While Not rst.EOF Set chl = Me.TreeView1.Nodes.Add(Relative:=nod, Relationship:=tvwChild, Text:=rst(fldName)) If level < UBound(arrLevels) Then AddChildren chl, level + 1 End If rst.MoveNext Loop rst.Close Set rst = Nothing End Sub
-
- PlatinumLounger
- Posts: 4470
- Joined: 26 Apr 2010, 17:36
Re: treeview - i'm on vb6
INSTEAD OF LOOP RST, if I use getrow an array, I get improvements in the speed of filling items?HansV wrote: ↑19 Jun 2024, 10:42Is this better?
Code: Select all
Private Sub Form_Load() Dim nod As MSComctlLib.Node Call APRI_CONN arrLevels = Array("[Z] & '-' & [ZONA]", "[REG] & '-' & [REGIONE]", _ "[PR] & '-' & [PROVINCIA]", "[ISTATEXT] & '-' & [COMUNE]") With Me.TreeView1 .LineStyle = tvwRootLines .Style = tvwTreelinesPlusMinusText .Nodes.Clear Set nod = .Nodes.Add(Text:="Italia") AddChildren nod, 0 End With End Sub Sub AddChildren(nod As MSComctlLib.Node, level As Long) Dim rst As ADODB.Recordset Dim fld As String Dim fldName As String Dim sql As String Dim chl As MSComctlLib.Node fld = arrLevels(level) fldName = "Level" & level sql = "SELECT DISTINCT " & fld & " AS Level" & level & " FROM Comuni_ISTAT" If level > 0 Then sql = sql & " WHERE " & arrLevels(level - 1) & "='" & Replace(nod.Text, "'", "''") & "'" End If Set rst = New ADODB.Recordset rst.Open Source:=sql, ActiveConnection:=CON, Options:=adCmdText Do While Not rst.EOF Set chl = Me.TreeView1.Nodes.Add(Relative:=nod, Relationship:=tvwChild, Text:=rst(fldName)) If level < UBound(arrLevels) Then AddChildren chl, level + 1 End If rst.MoveNext Loop rst.Close Set rst = Nothing End Sub
-
- PlatinumLounger
- Posts: 4470
- Joined: 26 Apr 2010, 17:36
Re: treeview - i'm on vb6
sal21 wrote: ↑19 Jun 2024, 12:03INSTEAD OF LOOP RST, if I use getrow and array, I get improvements in the speed of filling items?HansV wrote: ↑19 Jun 2024, 10:42Is this better?
Code: Select all
Private Sub Form_Load() Dim nod As MSComctlLib.Node Call APRI_CONN arrLevels = Array("[Z] & '-' & [ZONA]", "[REG] & '-' & [REGIONE]", _ "[PR] & '-' & [PROVINCIA]", "[ISTATEXT] & '-' & [COMUNE]") With Me.TreeView1 .LineStyle = tvwRootLines .Style = tvwTreelinesPlusMinusText .Nodes.Clear Set nod = .Nodes.Add(Text:="Italia") AddChildren nod, 0 End With End Sub Sub AddChildren(nod As MSComctlLib.Node, level As Long) Dim rst As ADODB.Recordset Dim fld As String Dim fldName As String Dim sql As String Dim chl As MSComctlLib.Node fld = arrLevels(level) fldName = "Level" & level sql = "SELECT DISTINCT " & fld & " AS Level" & level & " FROM Comuni_ISTAT" If level > 0 Then sql = sql & " WHERE " & arrLevels(level - 1) & "='" & Replace(nod.Text, "'", "''") & "'" End If Set rst = New ADODB.Recordset rst.Open Source:=sql, ActiveConnection:=CON, Options:=adCmdText Do While Not rst.EOF Set chl = Me.TreeView1.Nodes.Add(Relative:=nod, Relationship:=tvwChild, Text:=rst(fldName)) If level < UBound(arrLevels) Then AddChildren chl, level + 1 End If rst.MoveNext Loop rst.Close Set rst = Nothing End Sub
-
- Administrator
- Posts: 79287
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: treeview - i'm on vb6
The code ran fast on my PC as it is now, but you can try it of course.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4470
- Joined: 26 Apr 2010, 17:36
Re: treeview - i'm on vb6
no idea...HansV wrote: ↑19 Jun 2024, 10:42Is this better?
Code: Select all
Private Sub Form_Load() Dim nod As MSComctlLib.Node Call APRI_CONN arrLevels = Array("[Z] & '-' & [ZONA]", "[REG] & '-' & [REGIONE]", _ "[PR] & '-' & [PROVINCIA]", "[ISTATEXT] & '-' & [COMUNE]") With Me.TreeView1 .LineStyle = tvwRootLines .Style = tvwTreelinesPlusMinusText .Nodes.Clear Set nod = .Nodes.Add(Text:="Italia") AddChildren nod, 0 End With End Sub Sub AddChildren(nod As MSComctlLib.Node, level As Long) Dim rst As ADODB.Recordset Dim fld As String Dim fldName As String Dim sql As String Dim chl As MSComctlLib.Node fld = arrLevels(level) fldName = "Level" & level sql = "SELECT DISTINCT " & fld & " AS Level" & level & " FROM Comuni_ISTAT" If level > 0 Then sql = sql & " WHERE " & arrLevels(level - 1) & "='" & Replace(nod.Text, "'", "''") & "'" End If Set rst = New ADODB.Recordset rst.Open Source:=sql, ActiveConnection:=CON, Options:=adCmdText Do While Not rst.EOF Set chl = Me.TreeView1.Nodes.Add(Relative:=nod, Relationship:=tvwChild, Text:=rst(fldName)) If level < UBound(arrLevels) Then AddChildren chl, level + 1 End If rst.MoveNext Loop rst.Close Set rst = Nothing End Sub
possible:
ITALIA-(Numbers of zone)
1-PIEMONTE-(Numbers of province)
TO-TORINO-(numbers of comuni)
ecc...
-
- Administrator
- Posts: 79287
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: treeview - i'm on vb6
I'd stick with what works now. Adding the count is possible but complicated.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4470
- Joined: 26 Apr 2010, 17:36
-
- PlatinumLounger
- Posts: 4470
- Joined: 26 Apr 2010, 17:36
Re: treeview - i'm on vb6
curious...
How to count the last children item, in my case i need to count all ISTAT-COMUNE
MY TEST
Debug.Print TreeView1.nodes(0).children.Count
How to count the last children item, in my case i need to count all ISTAT-COMUNE
MY TEST
Debug.Print TreeView1.nodes(0).children.Count
-
- Administrator
- Posts: 79287
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4470
- Joined: 26 Apr 2010, 17:36
-
- Administrator
- Posts: 79287
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: treeview - i'm on vb6
You can change the Text property of a node (child) using code.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4470
- Joined: 26 Apr 2010, 17:36