Ease your developer’s life with list boxes

Automatically translated from English
Our main objective is to make developers’ lives easier, day after day, and list boxes are one 4D’s most used and powerful form objects that serve this purpose. We all know that list boxes trigger many events, that’s why in 4D v18 R2 we’ve enhanced the Form event command to return even more information when list box events are triggered.
 
Want to let go of your old tricky code for guessing which row, column, or header you clicked or put your mouse on? Let us show you a smoother and smarter way to do it!

HDI: Examples to work easily with Listbox events

Depending on the event, additional relevant properties are now returned by the Form event command.
 
Let’s check out some examples.

On header click event

The header object’s name, column object’s name and column number are now returned by the Form event command.
Here’s an example of the object returned when an On Header Click event is triggered/

{"headerName":"headerLastname", // New property - Header object name
"columnName":"lastname", // New property - Column object name
"column":2,   // New property - Column number
"code":42,
"description":"On Header Click",
"objectName":"EmployeesLB"}

For example, if you set a column object name with a real attribute name of a dataclass (e.g., lastname):

 

 

When clicking on the header of the column displaying the employees’ last name, we sort the column on the lastname and firstname attributes:

Form.event:=FORM Event
Case of
: (Form event code=On Header Click)
 if (Form.event.columnName="lastname")
  Form.employees:=Form.employees.orderBy(Form.event.columnName+", firstname")
 End if
End case
 

On DISPLAY DETAILS event

When the On Display Details event is triggered, additional relevant properties (e.g., isRowSelected) are now returned by the Form event command. This can be helpful to manage the appearance of a list box’s lines.
 
Below is an example of a method (setColor) set in the Meta info expression property of a list box:
 
 
The setColor method:
C_OBJECT($event;$0;$meta)
$event:=FORM Event
$meta:=New object
Case of
: ($event.code=On Display Detail)
 If ($event.isRowSelected) //set color when row is selected
  $meta.fill:="lightblue"
 End if
End case
$0:=$meta
 

And here’s how the list box looks when rows are selected:

 

On mouse move EVENT

Another frequently used event is the On Mouse Move event. Below are examples of objects returned by the Form event command when it’s triggered.

You immediately get useful properties to locate where you put your mouse!

The mouse hovers over a header

Form event command returns:

{"area":"header", // The mouse is on a header
"areaName":"headerLastname", // Header object name
"column":2, //  Column number
"columnName":"lastname", // Colmun object name
"code":37,
"description":"On Mouse Move",
"objectName":"EmployeesLB"}

 

The mouse hovers Over a cell

Form event command returns:

{"area":"cell", // The mouse is on a cell
"column":1, //  Column number
"row":2, //  Row number
"columnName":"firstname", // Colmun object name
"code":37,
"description":"On Mouse Move",
"objectName":"EmployeesLB"}
 
There are so many list box events that a single blog post is not enough to cover them all, so be sure to check the documentation to find extensive information about each event and download the HDI to learn more!
 
 
 
 
Avatar

• Product Owner •

Marie-Sophie Landrieu-Yvert has joined the 4D Product team as a Product Owner in 2017. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.

Marie-Sophie graduated from the ESIGELEC Engineering School and began her career as an engineer at IBM in 1995. She participated on various projects (maintenance or build projects) and worked as a Cobol developer. Then she worked as an UML designer and Java developer. Lately her main roles were analyzing and writing functional requirements, coordinate business and development teams.