Results 1 to 4 of 4

Thread: search text in treeview

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2011
    Posts
    17

    search text in treeview

    Private Sub Form_Load()
    TV.ImageList = ImageList1

    TV.Nodes.Add , , , "sanu", 1 'add text and image from imagelist1
    TV.Nodes.Add , , , "test", 1
    TV.Nodes.Add , , , "strip", 1
    TV.Nodes.Add , , , "list", 1
    TV.Nodes.Add , , , "view", 1
    TV.Nodes.Add , , , "time", 1
    TV.Nodes.Add , , , "now", 1
    TV.Nodes.Add , , , "yes", 1
    End Sub

    TextToSearch = "yes"

    dim X as integer
    for X = 0 to TV - 1
    if TextToSearch = TV.nodes(x).text ' allways end up with error
    next X

    Note : i wanna search the text and remove TextTosearch and the image

    Help me please VB6 master...

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: search text in treeview

    Try this
    vb Code:
    1. TextToSearch = "strip"
    2.    
    3.     Dim X As Integer
    4.     For X = TV.Nodes.Count To 1 Step -1
    5.         If TextToSearch = TV.Nodes(X).Text Then
    6.             TV.Nodes.Remove X
    7.         End If
    8.     Next X

    Notes:
    1- Nodes lower bound is 1 not 0
    2- When you need to remove node inside a loop, you must use reverse order loop.



  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2011
    Posts
    17

    Resolved Re: search text in treeview

    Quote Originally Posted by 4x2y View Post
    Try this
    vb Code:
    1. TextToSearch = "strip"
    2.    
    3.     Dim X As Integer
    4.     For X = TV.Nodes.Count To 1 Step -1
    5.         If TextToSearch = TV.Nodes(X).Text Then
    6.             TV.Nodes.Remove X
    7.         End If
    8.     Next X

    Notes:
    1- Nodes lower bound is 1 not 0
    2- When you need to remove node inside a loop, you must use reverse order loop.
    this is work like a charm...Thanks a lot and mark as solved...

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: search text in treeview

    As you now have it sorted out, could you please do us a little favour, and mark the thread as Resolved?
    (this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)

    You can do it by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved". (like various other features of this site, you need JavaScript enabled in your browser for this to work).

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width