Announcement

Collapse
No announcement yet.

TreeView Walkthrough in just 15 lines of code - PBWin9

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • TreeView Walkthrough in just 15 lines of code - PBWin9

    <deleted> meant to put it in Source Code forum.

    Since this posting, I reduced the line count even more - see the discussion further down this thread.
    Last edited by Gary Beene; 6 Apr 2009, 09:36 PM.

  • #2
    Could be used as discussion for the subject though
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

    Comment


    • #3
      Actually, I would be interested in hearing from anyone who uses the code. I tried a few versions of tree structures and it seemed to work for them all, but I'd enjoy hearing how it worked from someone else.

      And without being too Perl-ish about it, I was just looking at the earlier version and realized I could take out another 2 lines and a variable declaration.

      Here's the revised version. Now we're talking about minimal code - only 11 lines of code if you don't count the SUB/DIM/End Sub statements!

      Code:
      Sub TreeWalk2(ByVal hWnd As Dword, ByVal hNode As Dword)
         Dim iReturn As Dword, hSibling As Dword
         Do
              Treeview Get Child hWnd, %ID_Treeview, hNode To iReturn                    'get child (1st choice)
              If iReturn = 0 Then Treeview Get Next hWnd, 100, hNode To iReturn 'or sibling (2nd choice)
              If iReturn = 0 Then                                               'no child or sibling
                  Do      'get sibling of first parent with sibling
                     Treeview Get Parent hWnd, %ID_TreeView, hNode To hNode            'parent
                     Treeview Get Next hWnd, %ID_TreeView, hNode To iReturn            'sibling child of parent
                  Loop Until iReturn Or (hNode = 0)  'stop when find sibling of parent with sibling, or no more choices
              End If
              hNode = iReturn    'possible values: 0, zero (no parent/no sibling), <>0 (parent or sibling)
              Sleep 250 : If iReturn Then Treeview Select hWnd, %ID_TreeView, hNode
         Loop While hNode
      End Sub
      That is of course, if no one finds a Tree it won't work on.

      For those of you needing more comments than those I put in the code, here's how it works.

      Starting at any node, it looks down the tree for a child. If no child if found, then it looks for a sibling. Following a child gets precedence over following a sibling.

      If no child or sibling exists, it goes up the tree looking for the first parent which has a sibling. When the bottom of the tree is reached, there are no more parents with siblings.
      Last edited by Gary Beene; 6 Apr 2009, 09:39 PM.

      Comment


      • #4
        Originally posted by Gary Beene View Post
        Here's the revised version. Now we're talking about minimal code - only 11 lines of code if you don't count the SUB/DIM/End Sub statements!
        Not to be a noodge but my editor counts 13 lines (12 wo the Sleep 250)
        [quote]


        Code:
           Do
                Treeview Get Child hWnd, %ID_Treeview, hNode To iReturn                    'get child (1st choice)
                If iReturn = 0 Then Treeview Get Next hWnd, 100, hNode To iReturn 'or sibling (2nd choice)
                If iReturn = 0 Then                                               'no child or sibling
                    Do      'get sibling of first parent with sibling
                       Treeview Get Parent hWnd, %ID_TreeView, hNode To hNode            'parent
                       Treeview Get Next hWnd, %ID_TreeView, hNode To iReturn            'sibling child of parent
                    Loop Until iReturn Or (hNode = 0)  'stop when find sibling of parent with sibling, or no more choices
                End If
                hNode = iReturn    'possible values: 0, zero (no parent/no sibling), <>0 (parent or sibling)
                Sleep 250 
                If iReturn Then Treeview Select hWnd, %ID_TreeView, hNode
           Loop While hNode
        ==================================
        "What we are today
        comes from thoughts of yesterday,
        and our present thoughts
        build our life of tomorrow:
        our life is the creation
        of our minds."
        Buddha
        ==================================
        It's a pretty day. I hope you enjoy it.

        Gösta

        JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
        LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

        Comment

        Working...
        X