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

node's occurences in a treeview

Status
Not open for further replies.

231166

Programmer
Apr 5, 2005
104
0
0
FR
Hi,

I have created a treeview called [blue]Treeview1[/blue].It contains terms.
Each term of this treeview is inserted once in the table TERMES of the Database, even if this term appears twice or three times in the treeview.
[blue]Now i need to test if one term appears one or two or more times in the Treeview1.[/blue]


I have created a sub which permit to find if a node exists between its parent and the root node but not in the entire TreeView1; but it does not permit me to count how many occurences of a selected node are in the treeview.


Could you help me to test this.

Thanks a lot from you.
Regards.

Nathalie




 
Hi Nathalie:

I've tested this, but I'm sure you'll have to modify it to meet your needs.

Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim T As TreeNode
        Dim i As Int16
        For i = 1 To 10
            T = New TreeNode("TERMES" & i)
            TreeView1.Nodes.Add(T)
        Next

    End Sub

    Sub CheckNodes()
        Dim i As Int16, j As Int16, k As Int16
        j = TreeView1.GetNodeCount(True)
        For i = 0 To j - 1
            If Mid(TreeView1.Nodes(i).Text, 1, Len(TreeView1.Nodes(i).Text) - 1) = "TERMES" Then
                k += 1
            End If
        Next

        MsgBox("TERMES occurred " & k & " times in the treeview.")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        CheckNodes()
    End Sub

This code returns 9 instances of Termes, because I asked it to remove only one character at the end to see if they matched.


I hope this helps.

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Hi, Thanks a lot for your help.

Yes,j i will adapt it to my needs.
I will tell you if it works.

Regards.
Nathalie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top