KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Popup menus and 4D v12 Listboxs
PRODUCT: 4D | VERSION: 12.2 | PLATFORM: Mac & Win
Published On: June 3, 2011

There are times when the best 4D List Box User Interface (UI) technique is to limit a users input to a limited number of choices. Possibly the best widget for this is the Popup menu. This Tech Tip documents and demonstrates two techniques for adding a Popup menu to a List Box, as illustrated by the two images below:



  1. To create a column with an included popup menu, first create a Choice List using the Tool Box.


  2. Then in the Property List for the List Box Column object of choice assign that Choice List as a Required List as shown below.


For a technique that gives more options of what could be done from a Popup menu widget, consider the technique below.



The code below demonstrates how columns were added to the List Box, how images were added to a column with images that give the user the indication that clicking will produce a popup menu, and finally adding desired information into the column or columns of choice based on the item choice the user makes.

One additional benefit of this technique is that the items' list string that is used with the Pop up menu function can be built on the fly, providing great flexibility to the the choices available to the user.

//method_wide_constants_declarations
ARRAY BOOLEAN(Listbox_aB;0)
C_INTEGER(HeaderPop_I;HeaderPic_I)
//--------------------------------------------------------------------------------
//local_variable_declarations

C_LONGINT($Ndx;$SOA;$RIS;$FormEvt_L;$Last;$Column_L;$Row_L;$UserChoice_L)
C_POINTER($Self_P)
C_TEXT($Items_T)
//=========================== Initialize and Setup ===========================
$FormEvt_L:=Form event
$Self_P:=Self
//=========================== Method Actions ===========================
Case of
   : ($FormEvt_L=On Load)
      ARRAY TEXT(PopArray_aT;0)
      ARRAY PICTURE(PicArray_aG;0)
      $Last:=LISTBOX Get number of columns(Listbox_aB)
      LISTBOX INSERT COLUMN(Listbox_aB;$Last+1;"PopPic";PicArray_aG;"HeaderPic";HeaderPic_I)
      LISTBOX INSERT COLUMN(Listbox_aB;$Last+2;"Popup";PopArray_aT;"HeaderPop";HeaderPop_I)
      LISTBOX INSERT ROW(Listbox_aB;1)
      LISTBOX INSERT ROW(Listbox_aB;2)
      LISTBOX SET ROWS HEIGHT(Listbox_aB;32)
      LISTBOX SET COLUMN WIDTH(*;"Column1";100)
      LISTBOX SET COLUMN WIDTH(*;"PopPic";32)
      
      GET PICTURE FROM LIBRARY("Popup_Win";PicArray_aG{1})
      GET PICTURE FROM LIBRARY("Popup_Mac";PicArray_aG{2})
      
      OBJECT SET TITLE(HeaderPop_I;"My Column")
   
    //-------------------------------------------------------------------------------
   : ($FormEvt_L=On Clicked)
      If (Listbox_aB>0)
         LISTBOX GET CELL POSITION(Listbox_aB;$Column_L;$Row_L)
         If ($Column_L=2)
            $Items_T:="Item #1            $UserChoice_L:=Pop up menu($Items_T)
            Case of
               : ($UserChoice_L=1)
                  PopArray_aT{Listbox_aB}:="Item 1"
               : ($UserChoice_L=3)
                  PopArray_aT{Listbox_aB}:="Item 3"
               : ($UserChoice_L=5)
                  PopArray_aT{Listbox_aB}:="Item 5"
               Else
                  PopArray_aT{Listbox_aB}:=""
            End case
         End if
      End if
End case