Results 1 to 5 of 5

Thread: Find Node in TreeView

  1. #1

    Thread Starter
    Fanatic Member khalik_ash's Avatar
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    724

    Find Node in TreeView

    hi

    as we can get the node in vb6 i need the VB.net

    Code:
    'VB6 code
    dim Nd as Nde
    
    set Nd=Treeview.nodes("Khalik") ' khalik is the key
    simple i need to find out if the node already created..
    if not i need to add node or skip it....

    is there away to find node

  2. #2
    Addicted Member
    Join Date
    Feb 2002
    Location
    closed
    Posts
    196
    simply trap the error that you will receive if you try to add a node with a key that already exists and deal with it in the catch block - i.e. flag a message or generate a new unique id and retry etc.

    Cheers..

  3. #3

    Thread Starter
    Fanatic Member khalik_ash's Avatar
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    724
    Originally posted by powdir
    simply trap the error that you will receive if you try to add a node with a key that already exists and deal with it in the catch block - i.e. flag a message or generate a new unique id and retry etc.

    Cheers..
    thanks powdir .. i belive u got it wrong...

    before i add a node to treeview i need to find out if exists i need to do diff operation and if not then add the node...

    i know if i loop around the nodes collection i can find that but do we have a method which does the job....?

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    No there is no intrinsic method to find a node. You'll need to write one.

    Here is a previous post on the subject:
    http://www.vbforums.com/showthread.p...hreadid=236652

  5. #5

    Thread Starter
    Fanatic Member khalik_ash's Avatar
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    724
    might be of use to some one like me........

    well i have written 2 sample function for finding the node
    first will return Boolean wheather Node Found or Not.

    Second function Return the Node.

    Code:
    Function TV_FindNode(ByVal nNode As TreeNodeCollection, ByVal Str As String) As Boolean
            Dim n As TreeNode
            For Each n In nNode
                If n.Text = Str Then
                    n.Text = Str
                    Return True
                    '     Exit For
                End If
            Next
            Return False
        End Function
        Function TV_FindRetNode(ByVal nNode As TreeNodeCollection, ByVal Str As String) As TreeNode
            Dim n As TreeNode
            For Each n In nNode
                If n.Text = Str Then
                    n.Text = Str
                    Return n
                End If
            Next
        End Function

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