KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Double-click a list box to add a row and enter the edit mode
PRODUCT: 4D | VERSION: 12.3 | PLATFORM: Mac & Win
Published On: April 13, 2012

The method below, LB_On_Double_Click, will add the functionality to a list box that when the user double-clicks below the last row in a list box, a new row will be appended and the cell in the column double-clicked will enter the edit mode.

If (True)
  If (False)
    Begin SQL
      /*
      LB_On_Double_Click

      Purpose: On Double Click, add a row to an array and enter edit mode
      */

    End SQL
  End if
  C_TEXT($MethodName_T)
  $MethodName_T:=Current method name
  //================ Declare Variables ================
  //method_parameters_declarations
  //---------------------------------------------------
  //method_wide_constants_declarations
  //---------------------------------------------------
  //local_variable_declarations

  C_LONGINT($Ndx;$SOA;$Col;$Row;$Params_L;$Type_L)
  C_TEXT($Obj_T)
  C_POINTER($ColVar_P)
End if
  /================ Initialize and Setup ================
$Params_L:=Count parameters

  //================ Method Actions ================

If (Asserted($Params_L=0;"Double-click beyond last listbox row"))

    // Get the name of the column variable
    // (
  $Obj_T:=OBJECT Get name(Object current)
    // )

  If ($Obj_T#"")

    LISTBOX GET CELL POSITION(*;$Obj_T;$Col;$Row;$ColVar_P)
    $Type_L:=Type($ColVar_P->)
    If (($Row=0) & \
        (($Type_L=Text array) | \
        ($Type_L=String array) | \
        ($Type_L=LongInt array) | \
        ($Type_L=Real array) | \
        ($Type_L=Date array)))

      $SOA:=LISTBOX Get number of rows(*;$Obj_T)+1
      LISTBOX INSERT ROW(*;$Obj_T;$SOA)

      // Begin to edit in the new cell
      // (

      EDIT ITEM($ColVar_P->;$SOA)
      // )

    End if
  End if
End if