Results 1 to 10 of 10
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Find NODE and SUB NODE ROOT NODE in treview (6.0)

    Please don't use <!t>[script] ... <!t>[/script] tags - they are NOT for code, they make the text almost unreadable.
    Please use <!t>
    Code:
     ... <!t>
    tags or <!t>[pre] ... <!t>[/pre] tags.
    HansV


    I use this code to find in tree of treeview a valu (in tbox1), i want to insert in msgbox after the var sfind the root, sub node wehre is founf the value...
    In this case the msgbox is "found 02413125L in 6500 - SALERNO and in 8505 - REGIONE SUD"
    <pre>'''''this is the code to find:
    Private Sub Command1_Click()

    Dim sfind As String
    Dim I As Integer

    sfind = Trim(Me.Text1.Text)
    For I = 1 To Form1.TreeView1.nodes.Count
    If InStr(1, Left(Form1.TreeView1.nodes(I).Text, 9), sfind, vbTextCompare) Then
    Form1.TreeView1.nodes(I).Selected = True
    'Form1.TreeView1.Nodes(I).Expanded = True
    Form1.TreeView1.SelectedItem.ForeColor = vbRed
    MsgBox ("TROVATO " & sfind)
    Exit Sub
    End If
    Next I


    End Sub

    '''' this is the code to create the treeview:
    Private Sub Form_Load()

    Dim bOpen As Boolean
    Dim sValue As String
    Dim sKey As String
    Dim nod As Node
    Dim nod2 As Node
    Dim nod3 As Node
    Dim I As Long

    If Not ADOOpenConnection(App.Path & "Past_Due_Test.mdb") Then
    Exit Sub
    End If

    With TreeView1
    ADOOpenRecordSet "Select * from AREA_TERR"
    ADO_RS.MoveFirst
    Do Until ADO_RS.EOF
    sValue = ADO_RS.Fields("COD_AREA").Value
    .nodes.Add , , "K" & sValue, sValue & " - " & ADO_RS.Fields("DESCRIZIONE"), 1, 1
    ADO_RS.MoveNext
    Loop
    ADO_RS.Close
    '
    ADOOpenRecordSet "Select * from SPORTELLI"
    ADO_RS.MoveFirst
    Do Until ADO_RS.EOF
    sKey = "K" & ADO_RS.Fields("REGIONE")
    sValue = ADO_RS.Fields("SPORT")
    If HasData(sValue) Then
    .nodes.Add sKey, tvwChild, "L" & sValue, sValue & " - " & ADO_RS.Fields("DESCRIZIONE"), 1, 2
    End If
    ADO_RS.MoveNext
    Loop
    ADO_RS.Close
    '
    ADOOpenRecordSet "Select * from DATI"
    ADO_RS.MoveFirst
    Do Until ADO_RS.EOF
    sKey = "L" & ADO_RS.Fields("PROVA2")
    sValue = ""
    For I = 1 To 8
    If I <> 2 Then
    sValue = sValue & ADO_RS.Fields("PROVA" & I)
    If I < 8 Then
    sValue = sValue & ", "
    End If
    End If
    Next
    .nodes.Add sKey, tvwChild, "M" & sKey & sValue, sValue, 1, 2
    .nodes(sKey).Parent.Bold = True
    ADO_RS.MoveNext
    Loop
    ADO_RS.Close
    ADOCloseConnection
    End With

    End Sub</pre>


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find NODE and SUB NODE ROOT NODE in treview (6.0)

    The parent of the node where the text is found (in your example 6500 - Salerno) is

    Form1.TreeView1.nodes(I).Parent

    and the parent of that node (in your example 8505 - Regione Sud) is

    Form1.TreeView1.nodes(I).Parent.Parent

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find NODE and SUB NODE ROOT NODE in treview (6.0)

    WORK!
    Sorry for code in tag script...;-)

  4. #4
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find NODE and SUB NODE ROOT NODE in treview (6.0)

    hummm...
    but if the string not is found in wich part of this code ia insert a msgbox ("non trovato!")

    Private Sub Command1_Click()

    Dim sfind As String, test() As String, TEST1 As String, TEST2 As String
    Dim I As Integer

    With TreeView1
    sfind = Trim(Me.Text1.Text)
    For I = 1 To Form1.TreeView1.Nodes.Count
    If InStr(1, Left(Form1.TreeView1.Nodes(I).Text, 9), sfind, vbTextCompare) Then
    Form1.TreeView1.Nodes(I).Selected = True
    Form1.TreeView1.SelectedItem.ForeColor = vbRed
    TEST1 = Form1.TreeView1.Nodes(I).Parent
    TEST2 = Form1.TreeView1.Nodes(I).Parent.Parent
    Form1.TreeView1.SelectedItem.ForeColor = vbRed
    MsgBox ("COPE " & sfind & " TROVATO *** " & " NELL'AREA " & TEST2 & " *** AGENZIA - " & TEST1)
    Exit Sub
    End If
    Next I
    End With

    End Sub

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find NODE and SUB NODE ROOT NODE in treview (6.0)

    Put in an Else part.

  6. #6
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find NODE and SUB NODE ROOT NODE in treview (6.0)

    Hans...
    Is possible to simulate via code the click event on item found?

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find NODE and SUB NODE ROOT NODE in treview (6.0)

    You can add a line

    TreeView1_NodeClick Form1.TreeView1.Nodes(I)

  8. #8
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find NODE and SUB NODE ROOT NODE in treview (6.0)

    i'm stupid...
    Tks as usual.

  9. #9
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find NODE and SUB NODE ROOT NODE in treview (6.0)

    Hans based the image is possible to count how many items have Regione sud and how many items have Salerno

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find NODE and SUB NODE ROOT NODE in treview (6.0)

    You can find the counts by using the appropriate SQL strings. For example
    <code>
    strSQL = "SELECT Count(*) AS Cnt FROM Sportelli WHERE REGIONE='Regione Sud'"
    </code>
    Open a recordset on this SQL string and look at the Cnt field.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •