Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adding nodes to a treeview from a table
Message
From
10/01/2007 06:01:27
 
 
To
09/01/2007 16:26:20
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 6
Miscellaneous
Thread ID:
01183973
Message ID:
01184106
Views:
22
>Any neat code to add the nodes for a treeview using a foxpro table? In this table I have the relative, relation and ckey, so I'd know the order of my treeview.
>
>And where to put this in the form?
>
>Currently I have the code below to add nodes from a table, and I placed it in my form's activate. Is this right?
>
>
>sele treeview
>=tableupdate(.t.)
>go top
>o = thisform.oletreeview.nodes
>o.clear
>
>scan
>	if alltrim(crelative) == '0'
>		o.add(,1,alltrim(ckey),alltrim(ctext),0)
>	else
>		o.add(alltrim(crelative),4,alltrim(ckey), alltrim(ctext),0)
>	endif
>endscan
>
>
>
>In my form I have a simple add node button that adds a record to a table. Since I want my treeview to somewhat refresh (get the updated values of my table), I placed the code in the form's activate.
>
>Can you help me refine this code pls?
>
>Thanks.

Evelyn,

I would not put this code in the form's activate event. Switching from this form to another and then back would rebuild the treeview. Not sure that this is intended.

I would create a method that does this and call it when it needs to be called

A couple of suggestions. Set LockScreen = FALSE and hide the treeview while building it
&& untested code

#define TRUE .t.
#define FALSE .f.

local Success
Success = TRUE

local s
s = select(0)

Local obj, LockScreen, TreeviewVisible

with m.thisform
    LockScreen = .LockScreen
    .LockScreen = TRUE

    with .oletreeview
        TreeviewVisible = .Visible
        .Visible = FALSE
 
        with .Nodes
            =.Clear()
            
            select treeview
            scan all while m.Success
               
               obj = null && Just in case
               do case
               case inlist(crelative, '0')
                  obj = .add(,1,rtrim(ckey),rtrim(ctext),0)
               
               otherwise
                  obj = .add(rtrim(crelative),4,rtrim(ckey), rtrim(ctext),0)
               
                endcase

               do case
               case !inlist(vartype(m.obj), T_OBJECT)
                  assert FALSE
                  Success = FALSE

               otherwise
                  with m.obj
                      && .ExpandedImage = ...
                      && .Bold = TRUE
                      && .backColor = ...
                      && .Expanded = TRUE

                  endwith

               endcase
            endscan
        endwith

        .Visible = m.TreeviewVisible 
    endwith

    .LockScreen = m.LockScreen

endwith

select (m.s)

return m.Success
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform