KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: View highlighted search result and auto scroll in the List Box
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: August 11, 2017

Here is a utility method to view search results retreived from Get edited text command that are highlighted and auto scrolled in a List Box:

// ---------------------------------------------------------------------------
// Name: VIEW_HIGHLIGHTED_SEARCH_AND_SCROLL_IN_LB
// Description: Method will highlight the records selected and scroll to the
// area that is visible in the List Box
// Parameter:
// $1 (POINTER) - Pointer to the field
// $2 (TEXT) - List Box object name
// --------------------------------------------------------------------------
C_POINTER($1;$fieldPtr;$table)
C_TEXT($2;$listBox)
ARRAY TEXT(arrW;0)
C_LONGINT($foundLoc)
C_TEXT($text)

If (Count parameters=2)
    $fieldPtr:=$1
    $table:=Table(Table($fieldPtr))
    $listBox:=$2
   
    $text:=Get edited text+"@"

    // Getting the highlight of the area
    SET QUERY DESTINATION(Into set;"$ListBoxSet")
    QUERY SELECTION ($table->;$fieldPtr->=$text)
    SET QUERY DESTINATION(Into current selection)
    HIGHLIGHT RECORDS($table->;"$ListBoxSet")
   
    // Move scroll to view in the List Box
    SELECTION TO ARRAY($fieldPtr->;arrW)
    $foundLoc:=Find in array(arrW;$text)
    OBJECT SET SCROLL POSITION(*;$listBox;$foundLoc+8)
End if


This is an example of using VIEW_HIGHLIGHTED_SEARCH_AND_SCROLL_IN_LB in a Variable Text's object method when triggering the "On after edit" form event. The text entered from the Variable Text is read into Get edited text command to search the record selection then scroll to the highlighted results in the List Box:

Case of
    : (Form event=On after edit)
    VIEW_HIGHLIGHTED_SEARCH_AND_SCROLL_IN_LB (->[Table_1]FirstName;"List Box")
End case


By typing "jer", it will find "Jerald" as it is looking the "FirstName" field:



This method can be inserted in a button to produce the same effect: