List boxes: Manage clicks in edited cells

As a developer, you’re used to handling events inside form objects. The most common is the on clicked form event which can be used in most objects, including list boxes. In this particular object, clicks can be managed either at the list box level itself or within the column methods.

And starting with 4D v18 R6, the on clicked form event is triggered whether a cell is being edited or not, giving you increased control and improving the interface.

Here is a very simple example:

You want to display possible values using a contextual menu for a cell when it’s being edited. However, when the row is simply selected, you want to offer a color choice for that particular row or cell.

It’s very simple to do this!

During the on clicked event, just check if the cell is being edited or not. Then depending on the result, display one menu or another!

If (Contextual click)  // you don't want to do anything if the click is not a contextual click
  If (Is editing text// if the text is being edited, suggest input values
    $dynMenu:=Create menu
    APPEND MENU ITEM($dynMenu; "Alpha")
    SET MENU ITEM PARAMETER($dynMenu; -1; "Alpha")
    APPEND MENU ITEM($dynMenu; "Bravo")
    SET MENU ITEM PARAMETER($dynMenu; -1; "Bravo")
    APPEND MENU ITEM($dynMenu; "Charlie")
    SET MENU ITEM PARAMETER($dynMenu; -1; "Charlie")
    $choice:=Dynamic pop up menu($dynMenu)
    If ($choice#"")
      // use the .row info present in the Form event object
      T1{FORM Event.row}:=$choice 
    End if 
  Else   // if the text is NOT being edited, suggest color for the text
    $dynMenu:=Create menu
    APPEND MENU ITEM($dynMenu; "Blue")
    SET MENU ITEM PARAMETER($dynMenu; -1; "Blue")
    APPEND MENU ITEM($dynMenu; "Green")
    SET MENU ITEM PARAMETER($dynMenu; -1; "Green")
    $choice:=Dynamic pop up menu($dynMenu)
    If ($choice#"")
       // use columnName and row attributes of the Form event object
      LISTBOX SET ROW COLOR(*; FORM Event.columnName; FORM Event.row; $choice)  
    End if 
  End if 
  RELEASE MENU($dynMenu)
End if

Find more details about form events in the doc center!

Compatibility note

If you already have code that runs during the on clicked event, you may want to stop the execution of that code when a click occurs inside an edited cell. In this case, simply test the state of this cell with the is editing text function in advance.

Check out the documentation for more technical details and join us on the 4D forum for any questions!

Roland Lannuzel
• Product Owner & 4D Expert •After studying electronics, Roland went into industrial IT as a developer and consultant, building solutions for customers with a variety of databases and technologies. In the late 80’s he fell in love with 4D and has used it in writing business applications that include accounting, billing and email systems.Eventually joining the company in 1997, Roland’s valuable contributions include designing specifications, testing tools, demos as well as training and speaking to the 4D community at many conferences. He continues to actively shape the future of 4D by defining new features and database development tools.