KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: A Method to Hide Data in Listboxes
PRODUCT: 4D | VERSION: 13.6 | PLATFORM: Mac & Win
Published On: July 2, 2015

Sometimes data presented in list boxes may contain information that some people may want to see while others may not, such as spoilers and results to certain events.

Below is a method to hide such data presented in a listbox allowing the user to view the data by clicking on it, it also requires that the listbox is only one line high be row.

//----------------------------------------------------------------
// Method: HideColumnData
//
// Description: Hides data in a column but allows users to reveal the data
// by clicking on the box
//
// Parameters:
// $1 - Name of the column to be hidden
// $2 - Form event
// $3 - Pointer to array process variable that will contain the string to
// mask the data
//
//----------------------------------------------------------------

C_TEXT($1;$col_t)
C_LONGINT($2;$event_l)
C_POINTER($3;$arr_p)

C_TEXT($formula_t;$tabName_t;$newFormula_t;$hiden_t)
C_LONGINT($tablenum_l;$i)
C_POINTER($table_ptr)

If (Count parameters=3)
  $col_t:=$1
  $event_l:=$2
  $arr_p:=$3
  LISTBOX GET TABLE SOURCE(*;$col_t;$tablenum_l)
  $tabName_t:=Table name($tablenum_l)
  $table_ptr:=Table($tablenum_l)

  Case of
    : ($event_l=On Load)
     $formula_t:=LISTBOX Get column formula(*;$col_t)
     RESOLVE POINTER($arr_p;$arrName_t;$notUsed1_l;$notUsed2_l)

     $hiden_t:="<SPAN STYLE=\"font-weight:Bold;color:Blue\">[Show]</SPAN>\n"
     For ($i;1;Records in selection($table_ptr->))
      APPEND TO ARRAY($arr_p->;$hiden_t)
     End for

     $newFormula_t:=$arrName_t+"{Record number(["+$tabName_t+"])+1}+"+$formula_t

     LISTBOX SET COLUMN FORMULA(*;$col_t;$newFormula_t;Is text)
     REDRAW(OBJECT Get pointer(Object current)->)

    : ($event_l=On Clicked)
     GOTO SELECTED RECORD($table_ptr->;Selected record number($table_ptr->))
     $arr_p->{Record number($table_ptr->)+1}:=""
     REDRAW(OBJECT Get pointer(Object current)->)

  End case
End if

To use the method, add it to the listbox's method of the column to hide and pass the column's object name as the first parameter, the form event as the second parameter and pass a pointer to it for the third parameter. It should be added in the On Load where the array is created and the On Clicked events for the listbox like in the example below:
//Column2 is the name of the column object
Case of
   : (Form event=On Load)
   ARRAY TEXT(arr_at;0)
   HideColumnData ("Column2";Form event;->arr_at)

   : (Form event=On Clicked)
   HideColumnData ("Column2";Form event;->arr_at)
End case


When the listbox is loaded it will look like the image below:


Then if the user clicks on "[Show]" it will reveal the winner of the game:


Also reordering does not effect which items have been revealed or not, it will maintain based on the record number and not the selected record number.*

Below is the listbox will all winners revealed:


The provided method uses Multistyled Text but doesn't have to, and to change the hidden form of the data just modify the $hidden_t variable in the HideColumnData method.

*About Record numbers and Selected Record Numbers:
http://doc.4d.com/4Dv14R5/4D/14-R5/About-Record-Numbers.300-1851816.en.html