listbox - expand/collapse (OpenInsight 32-bit Specific)
At 25 JUL 2002 07:54:21AM Charles DiCarlo wrote:
This is probably a simple one, but I'm stumped.
My opening form contains a listbox.
The listbox is always displayed expanded, but here is what I am trying to do:
First time a user logs on, the listbox should be collapsed. After that, the list box should default to where it was prior to opening another form, report, etc. until the user logs out. Thanks.
At 25 JUL 2002 08:45AM Oystein Reigem wrote:
Charles,
The ingredients you need is
- how to collapse your list box so just the first level nodes show
- how to save the state of the list box (information about which nodes are collapsed and which are expanded)
- how to restore the state of the list box.
The first one is easy:
RetVal=Send_Message( @Window : ".LB", "EXPAND", 0, 1 )
The second one is easy:
List_Ex=Get_Property( @Window : ".LB", "LIST_EX" )
…store List_Ex somewhere safe…
The third one might be tricky. I don't think you can just reset LIST_EX. I think you must must loop through all the entries in LIST_EX (all the lines of the list box) and expand each one individually.
- Oystein -
At 25 JUL 2002 09:06AM Oystein Reigem wrote:
DiCarlo
Correction: I meant SELPOS_EX - not LIST_EX.
- Oystein -
At 25 JUL 2002 09:28AM Oystein Reigem wrote:
F* i h j f* d*!
Sorry, Charles. Too long since I worked with this stuff. SELPOS_EX knows about the expand/collapse state of the selected line - not all lines. So I guess ingredient 2 has to
- init an array with info about the state of all visible lines
- loop through all visible lines (use LIST property) from the top downwards
- select each visible line in turn (SELPOS property)
- get the expand/collapse state of the line (from the SELPOS_EX property)
- append that info to the array
- remember the array
Ingredient 3 can then
- get the array
- start with setting the list box content fully expanded (EXPAND message with paramater 0=all)
- loop through all the array elements (corresponding to the lines that shall be visible), working from the top downwards
- set the state of each visible line in turn (EXPAND message); some of the lines will be kept expanded (i.e, with sub-nodes visible), some will be told to collapse (i.e, their sub-nodes will hidden).
- Oystein -
At 25 JUL 2002 09:59AM Oystein Reigem wrote:
Charles,
I just went ahead and did the programming.
In my experimental setup I have one window with a hierarchical list box LB and three buttons - one for each process ("ingredient"). In the real world I assume process 1 and 3 could be in the CREATE of the window and process 2 in CLOSE. And 2 and 3 might have to use a different method than a common variable to save and store the state info.
1. Set collapsed:
$insert Logical
declare function Send_Message
RetVal=Send_Message( @Window : ".LB", "EXPAND", 0, 1 )
RETURN 0
2. Save state:
$insert Logical
declare function Get_Property
declare function Set_Property
/* state array */
common / HierListBoxState / State@
/* the visible lines */
List=Get_Property( @Window : ".LB", "LIST" )
/* how many visible lines? */
Num_Vis=count(List, @FM) + (List "")
/* save current SELPOS if necessary */
SelPos=Get_Property( @Window : ".LB", "SELPOS" )
/* init state array */
State@="
/* loop through all visible lines */
for I=1 to Num_Vis
/* get collapse/expand info for visible line I */
UnUsed=Set_Property( @Window : ".LB", "SELPOS", I )
SelPos_Ex=Get_Property( @Window : ".LB", "SELPOS_EX" )
Num_Leafs=SelPos_Ex
if Num_Leafs ] 0 then
/* sub-nodes are visible */Expanded=true$end else
/* sub-nodes are not visible. current line is either collapsed or is a leaf node */Expanded=false$end
/* append to state array */
State@[i]=Expanded
next I
/* restore current SELPOS if necessary */
UnUsed=Set_Property( @Window : ".LB", "SELPOS", SelPos )
RETURN 0
3. Restore state:
$insert Logical
declare function Get_Property
declare function Set_Property
declare function Send_Message
/* state array */
common / HierListBoxState / State@
/* totally expand the list box */
RetVal=Send_Message( @Window : ".LB", "EXPAND", 0, 999 )
/* how many visible lines shall there be? */
Num_Vis=count(State@, @FM) + (State@ "")
/* loop through all visible lines (all lines that are to stay visible) */
for I=1 to Num_Vis
/* set collapse/expand state for visible line I */
Expanded=State@[i]
if not(Expanded) then
/* collapse line */RetVal=Send_Message( @Window : ".LB", "EXPAND", I, 0 )end
next I
RETURN 0
- Oystein -
At 25 JUL 2002 10:24AM Charles DiCarlo wrote:
Thanks so much Oystein. I'll give it a shot.