Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Re: Please Help with TreeView population


Message #1 by "cdebiasio@t... on Fri, 14 Jun 2002 19:31:30 +0200 (CEST)
Dear All;

I have a MS Access database table called TUSERGROUPS with the following 
fields:
- TUSERGROUP_ID (Primary Key, AutoNumber)
- GROUPNAME     (String)
- TPARENT_ID    (Integer)

The purpose is that multiple sub groups can be added to a group, i.e.
SALES DEPARTMENT               (TUSERGROUP_ID = 1,  TPARENT_ID = 0)
 - Pretoria                    (TUSERGROUP_ID = 3,  TPARENT_ID = 1)
   - Corporate Sales           (TUSERGROUP_ID = 4,  TPARENT_ID = 3)
     - Small Corporates        (TUSERGROUP_ID = 5,  TPARENT_ID = 4)
     - Big Corporates          (TUSERGROUP_ID = 6,  TPARENT_ID = 4)
   - Retail Sales              (TUSERGROUP_ID = 7,  TPARENT_ID = 3)
 - Johannesburg                (TUSERGROUP_ID = 8,  TPARENT_ID = 1)
   - Corporate Sales           (TUSERGROUP_ID = 9,  TPARENT_ID = 8)
     - Small Corporates        (TUSERGROUP_ID = 10, TPARENT_ID = 9)
     - Big Corporates          (TUSERGROUP_ID = 11, TPARENT_ID = 9)
   - Retail Sales              (TUSERGROUP_ID = 12, TPARENT_ID = 8)
IT DEPARTMENT                  (TUSERGROUP_ID = 2,  TPARENT_ID = 0)
 - Pretoria                    (TUSERGROUP_ID = 13, TPARENT_ID = 2)
 - Johannesburg                (TUSERGROUP_ID = 14, TPARENT_ID = 2)

I really hope this is not to difficult or rather that I explained it well.

Now, I need to get all of this into a treeview control.  I managed to make 
a root note with the text "User Groups" and to add the Main Groups with 
the following code:

strL = "Select * from TUSERGROUP where TPARENT_ID = 0 order by 
TUSERGROUP_ID"
sMainGroups.Open strL, cn, adOpenDynamic, adLockOptimistic
Do Until rsMainGroups.EOF
      Set mNode = TreeView1.Nodes.Add(1, tvwChild)
      mNode.Text = rsMainGroups!groupname
      arrID(G) = rsMainGroups!TUSERGROUP_ID
      rsMainGroups.MoveNext
      G = G + 1
  Loop
rsMainGroups.Close
Set rsMainGroups = Nothing

This works fine, I get the Main Groups under the root "User Groups"

Now the question (at long last one may say):
--------------------------------------------
How do I get the sub groups under the groups so that it looks like the 
sample above (obvious only the GROUPNAME fields). Thus, how do I get each 
sub group under it's main group.  

It's currently a bit advanced for me, and trust me, I tried now the whole 
day and just don't manage.

Your assistance will really be appreciated.  If I did not explain it well 
enough please let me know - I really need help on this one.

Regards
Helga

  Return to Index