The difference between ItemLostFocus, Column LostFocus and Grid LostFocus events

Date:12 September 2007
Product/Release:Visual LANSA - All Versions
Abstract:An explanation for why the ItemLostFocus event is not always fired when expected
Submitted By:LANSA Technical Support

Description:

In a form/reusable part which performs validation or some other action when the user finishes editing a cell in a grid, you might typically add the validation code into an ItemLostFocus event for the grid. This means that if the user clicks/tabs to another record in the grid, the ItemLostFocus event will be fired. However if the user clicks on another cell in the same row, the event will not fire. Furthermore, if the cell loses focus by the user clicking somewhere on the form outside the grid (for example, clicking on a button or field), the ItemLostFocus event will also not fire.

Explanation:

ItemLostFocus event
The ItemLostFocus event does not refer to Windows focus. It actually means "Another Item/Row in the list has got focus". In the example above, when the user clicked outside of the grid, the focus item in the grid has not changed, therefore the event will not fire. However, if the user clicked on another row within the grid then the event would be fired.

Column LostFocus event
The ItemLostFocus event is fired when the user clicks on another row. But if you want to capture the event when a user moves to another cell within the same row, you must make use of the Column LostFocus event. This is triggered when the active Column is changed (again, this will not be triggered if the user clicks outside the grid). Each column has its own LostFocus event so you should handle the event for each editable column.

Grid LostFocus event
This is triggered whenever the user moves focus from within the grid, to an item outside the grid. Even if the user clicks on another Windows application, this event will be triggered. The event is not triggered if the user moves between cells within the grid.

In the case where there validation must be performed as soon as the user has finished editing a cell, you must handle all 3 events; this can be done with a single EVTROUTINE call as shown below:

EVTROUTINE HANDLING(#GRID_1.LostFocus #GRID_1.ItemLostFocus #GDCL_1.LostFocus #GDCL_2.LostFocus #GDCL_3.LostFocus)
ENDROUTINE

This will fire the event as soon as the user clicks on anything outside the cell that they are editing whether it is inside the grid, on the form or elsewhere in Windows.