Tech Tip: Utility Method to Obtain Hierarchical Listbox Information On Mouse Move
PRODUCT: 4D | VERSION: 15.3 | PLATFORM: Mac & Win
Published On: March 24, 2017
Below is a utility method which will return the column (which is also the array for the hierarchy level), the row (which is also the element of the array) and also the pointer to the specific element which the mouse cursor is over. This method can be used with the On Mouse Move event to highlight specific rows and get specific data.
// Util_LISTBOX_GET_MOUSE_HIER // // Details: // Returns the element details of a row // which has been hovered by the mouse cursor // // Parameters: // $1 - Pointer to Hierarchical List Box // Output: // $2 - Pointer To Pointer to Receive Pointer to Specific Array and Element // $3 - Pointer To Longint to Receive Column Number (aka Hier Array Level) // $4 - Pointer To Longint to Receive Row Number (aka Array Element) C_POINTER($1;$lbPtr) C_POINTER($2;$resElem_p) C_POINTER($3) C_LONGINT($resCol_l) C_POINTER($4) C_LONGINT($resRow_l) If (Count parameters>1) ARRAY POINTER($hierVar_ap;0) C_BOOLEAN($heir_B) C_LONGINT($rowCount_l) C_LONGINT($colCount_l) C_LONGINT($mX;$mY;$mB) C_LONGINT($lbBTrack) C_LONGINT($rowStart_l) C_LONGINT($lbL;$lbT;$lbR;$lbB) C_LONGINT($tblNum;$fldNum) C_TEXT($varName) C_TEXT($fomula_t) $lbPtr:=$1 $rowCount_l:=LISTBOX Get number of rows($lbPtr->) LISTBOX GET HIERARCHY($lbPtr->;$hier_B;$hierVar_ap) If ($hier_B=True) $colCount_l:=Size of array($hierVar_ap) GET MOUSE($mX;$mY;$mB) OBJECT GET COORDINATES($lbPtr->;$lbL;$lbT;$lbR;$lbB) $headerH_l:=LISTBOX Get information($lbPtr->;lk header height) $footerH_l:=LISTBOX Get information($lbPtr->;lk footer height) $hsH_l:=LISTBOX Get information($lbPtr->;lk hor scrollbar height) $vsW_l:=LISTBOX Get information($lbPtr->;lk ver scrollbar width) If (($mX>=$lbL)&($mX<=($lbR-$vsW_l))&($mY>=($lbT+$headerH_l))&($mY<=(($lbB-$footerH_l)-$hsH_l))) $resRow_l:=1 $resCol_l:=1 $lbTrack:=0 $rowStart_l:=1 For ($col_l;1;$colCount_l) $lbBTrack:=0 For ($row_l;$rowStart_l;$rowCount_l) LISTBOX GET CELL COORDINATES($lbPtr->;$col_l;$row_l;$lbL;$lbT;$lbR;$lbB) Case of : ((($mY>$lbT) & ($mY<=$lbB))|(($mY>=$lbT)&($my<$lbB))) $resRow_l:=$row_l $resCol_l:=$col_l RESOLVE POINTER($hierVar_ap{$col_l};$varName;$tblNum;$fldNum) $fomula_t:="$resElem_p:=->"+$varName+"{"+String($row_l)+}"" EXECUTE FORMULA($fomula_t) $col_l:=$colCount_l $row_l:=$rowCount_l : ($mY>$lbB) If ($lbB>$lbBTrack) $lbBTrack:=$lbB $rowStart_l:=$row_l End if : ($mY<$lbT) $row_l:=$rowCount_l End case End for End for $2->:=$resElem_p If (Count parameters>2) $3->:=$resCol_l $4->:=$resRow_l End if End if End if End if |
Below is an example of using the Method
For the following ListBox and Content:
![](https://kb.4d.com:443/kbase/assets/images/77738-1.jpg)
Converted to a Hierarchical List Box and then for the object method add:
If (Form event=On Mouse Move) C_POINTER($lbPtr) C_POINTER($VarPointer) C_LONGINT($col_l) C_LONGINT($row_l) C_TEXT($value_t) $lbPtr:=OBJECT Get pointer(Object named;"List Box") Util_LISTBOX_GET_MOUSE_HIER_ELEM ($lbPtr;->$VarPointer;->$col_l;->$row_l) If(Nil($VarPointer)=False) $value_t:=$VarPointer-> End if End if |
Below are some examples of where the mouse cursor is and the results from the method note that when the cursor is not on an item it returns a nil value for the pointer:
![](https://kb.4d.com:443/kbase/assets/images/77738-2.jpg)