Here's my stored procedure for refreshing list boxes.  You can install and use 
it as is, or use the idea to write your own code.  Watch for incorrectly 
wrapped lines in your email reader. -- Larry

------------------------------------------------------------------------------
-- RefreshListbox: Refreshes the rows in a list box from the database;
-- preserving sort order and position.  Returns new count of records.
-- pRLB_CompID must receive the component ID of the list box to refresh.
-- pRLB_Click can contain 'Y' if the calling program wants this procedure
-- to simulate a click on the current index.
-- If the list box where clause contains an ORDER BY phrase, ORDER BY
-- must be fully spelled out, and must be the last clause in the WHERE.
------------------------------------------------------------------------------
-- PUT RefreshListbox.PRC AS RefreshListbox pRLB_CompID TEXT(100) pRLB_Click 
TEXT(1) RETURN INTEGER
------------------------------------------------------------------------------

IF pRLB_CompID IS NULL THEN
  RETURN -1
ENDIF

SET VAR pRLB_ItemIndex TEXT = NULL
SET VAR pRLB_TopItem   TEXT = NULL
SET VAR pRLB_Where     NOTE = NULL
SET VAR pRLB_UserSort  TEXT = NULL
SET VAR pRLB_Count     TEXT = NULL

GETPROPERTY &pRLB_CompID ITEMINDEX         'pRLB_ItemIndex'
GETPROPERTY &pRLB_CompID TOPITEM           'pRLB_TopItem'
GETPROPERTY &pRLB_CompID LOOKUPWHERECLAUSE 'pRLB_Where'
GETPROPERTY &pRLB_CompID CURRENTSORT       'pRLB_UserSort'

-- If the user has applied a sort (by clicking the listview header), we need
-- to change the lookup where clause to the new sort.  If there's no sort on
-- the existing where clause, we add it.
IF pRLB_UserSort IS NOT NULL AND (SLEN(TRIM(pRLB_UserSort)) > 0) THEN
  IF pRLB_Where CONTAINS 'ORDER BY' THEN
    SET VAR pRLB_Where = (SGET(.pRLB_Where, 1, (SLOC(.pRLB_Where, 'ORDER BY'))) 
& 'ORDER BY' & .pRLB_UserSort)
  ELSE
    SET VAR pRLB_Where = (.pRLB_Where & 'ORDER BY' & .pRLB_UserSort)
  ENDIF
  DEBUG WRITE 'Listbox', .pRLB_CompID, 'New where =', .pRLB_Where
  PROPERTY &pRLB_CompID LOOKUPWHERECLAUSE .pRLB_Where
ENDIF

-- Perform refresh
PROPERTY &pRLB_CompID REFRESHLIST 'TRUE'

PROPERTY &pRLB_CompID TOPITEM .pRLB_TopItem

IF pRLB_Click = 'Y' THEN
  PROPERTY &pRLB_CompID MAKECLICK .pRLB_ItemIndex
ENDIF

GETPROPERTY &pRLB_CompID ITEMCOUNT 'pRLB_Count'

CLEAR VAR pRLB_% EXCEPT pRLB_Count

RETURN (INT(.pRLB_Count))

Reply via email to