dcsimg
Results 1 to 7 of 7

Thread: check if i have clicked on parent node in treeview

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,814

    check if i have clicked on parent node in treeview

    hpw to, if i check if i have clicked only a parent node in treeview, not subnode, not child. ecc...?

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,671

    Re: check if i have clicked on parent node in treeview

    Did you read the MSDN Help file on the Treeview Control?

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,929

    Re: check if i have clicked on parent node in treeview

    in the node click event
    Code:
    if node.Index= node.Root.Index then
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,545

    Re: check if i have clicked on parent node in treeview

    Quote Originally Posted by luca90 View Post
    hpw to, if i check if i have clicked only a parent node in treeview, not subnode, not child. ecc...?
    well how did you load the Treeview ?
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  5. #5
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    2,109

    Re: check if i have clicked on parent node in treeview

    "only a parent node in treeview, not subnode, not child. ecc"

    ...every node with children is a parent node, similarly, every node except the root is a child node.

    -Root(Parent)
    --Node1 (Parent of Node3, Child of Root)
    ---Node3
    --Node2

    And on and on and on. Can you be more specific about what type of node you're trying to isolate here?
    To determine if it's been clicked; obviously there's the .Expanded property... but if you still want the node counted as clicked if it's since been re-collapsed, there's an 'Expanded Once' property (which would also indicate the children nodes have been loaded if they didn't exist already)-- but you'd need API calls to retrieve it since VB doesn't have it built-in, TVIS_EXPANDEDONCE.

  6. #6
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,013

    Re: check if i have clicked on parent node in treeview

    Here's a little function I sometimes use. Maybe it'll help you:

    Code:
    
    Public Function NodeNestingLevel(ByVal oNode As Node) As Long
        Dim oNode2 As Node
        '
        Set oNode2 = oNode
        Do Until (oNode2.Parent Is Nothing)
            NodeNestingLevel = NodeNestingLevel + 1&
            Set oNode2 = oNode2.Parent
        Loop
    End Function
    
    

    With little imagination, it'll do what you want.

    Enjoy,
    Elroy

    EDIT1: It bugged me that I originally declared the return as an Integer, so I changed it (both here and in my primary project) to a Long.
    Last edited by Elroy; Jan 15th, 2019 at 09:09 PM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,601

    Re: check if i have clicked on parent node in treeview

    to piggyback on posts from both fafalone & Elroy...

    Question to clarify: how do you define a parent?

    If you want to know if the selected item is at the top level of the treeview:
    Code:
    If Treeview1.SelectedItem.Parent Is Nothing Then ' at top level
    The above handles typical "root" nodes as show in fafalone's post and also handles cases like this where there is no typical root
    - Hierarchy 1
    .. -- Child 1
    - Hierarchy 2
    .. -- Child 1
    - Hierarchy 3

    If you want to know if the current node has any children, there is a property for that: .Children
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width