KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to obtain the value of a selected cell in a selection based list box
PRODUCT: 4D | VERSION: 13.0 | PLATFORM: Mac & Win
Published On: June 8, 2012

This Technical Tip demonstrates a way to programmatically get the value of a cell in a selection based list box. The following method takes a pointer as a parameter which will point to the value of a selected cell in the list box object "List Box":

//Method: GET_SELECTED_CELL_VALUE

C_POINTER($1;$listBox_p)
C_POINTER($2;$col_p)
C_LONGINT($tableNum_l)
C_LONGINT($col_l;$row_l)

If (Count parameters=2)
 LISTBOX GET TABLE SOURCE($listBox_p->;$tableNum_l)
 LISTBOX GET CELL POSITION($listBox_p->;$col_l;$row_l)
 $col_p:=OBJECT Get pointer(Object current)
 GOTO SELECTED RECORD((Table($tableNum_l))->;$row_l)
 $2->:=$col_p->
End if


The above method should be called in the list box object method when the On Clicked form event is generated, as shown below:

//List Box object method

Case of
 : (Form event=On Clicked)
  C_TEXT($value_t)
  GET_SELECTED_CELL_VALUE (->List Box;->$value_t)
End case


Using the above code, selecting the cell in column two, row two in the following image would result in the variable $value_t equalling "record_B":