by Rick Lipkin » Fri Dec 14, 2007 2:21 pm
James
The list box is a listbox within a dialog that is activated from a Valid on a get. I think the ESC behavior is more a function of the Valid than the listbox .. however, I would like to 'trap' the ESC key press within the listbox and force the 'cancel' route .. here is a typical code snipit ..
REDEFINE GET oMTRPOOL VAR zMTRPOOL ID 135 of oGRPS PICTURE "@!" ;
when ( xSUPER = 'Y' .or. xADMIN = 'Y'.or. xMGR = 'Y' .or. xTECH = 'Y' );
valid MTRPGET( zMTRPOOL, cMODE, oMTRPOOL, oRsVEH, "VEHICLES", zPOOLID ) UPDATE // mtrpslct.prg
//----------------------
Func MTRPGET( cNAME, cMODE, oOBJ, oRs, cTABLE )
LOCAL oDLG,oLBX
LOCAL oBTN1,oBTN2,oBTN3
LOCAL oRsMTP, oErr, cSQL
IF cNAME = "ALL" .and. cMODE = 'R'
RETURN(.T.)
ENDIF
IF EMPTY( oOBJ )
oOBJ := " "
ENDIF
IF cMODE = "E"
DO CASE
CASE cTABLE = "AGENCY"
IF cNAME = oRs:Fields("MOTORPOOL"):Value .and.;
oRs:Fields("MOTORPOOL"):Value <> SPACE(LEN(oRs:Fields("MOTORPOOL"):Value))
RETURN(.T.)
ENDIF
CASE cTABLE = "VEHICLES"
IF cNAME = oRs:Fields("MOTORPOOL"):Value .and.;
oRs:Fields("MOTORPOOL"):Value <> SPACE(LEN(oRs:Fields("MOTORPOOL"):Value))
RETURN(.T.)
ENDIF
CASE cTABLE = "MPOOLOC"
IF cNAME = oRs:Fields("mtrpool"):Value .and.;
oRs:Fields("mtrpool"):Value <> SPACE(LEN(oRs:Fields("mtrpool"):Value))
RETURN(.T.)
ENDIF
ENDCASE
ENDIF
oRsMTP:= TOleAuto():New( "ADODB.Recordset" )
oRsMTP:CursorType := 1 // opendkeyset
oRsMTP:CursorLocation := 3 // local cache
oRsMTP:LockType := 3 // lockoportunistic
cSQL := "SELECT * FROM MTRPOOL where AGENEID = '"+xAGENEID+"' order by AGENCY,MTRPOOL"
TRY
oRsMTP:Open( cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )
CATCH oErr
MsgInfo( "Error in Opening MTRPOOL table" )
RETURN(.F.)
END TRY
IF EMPTY( cNAME )
cNAME := "BOGUS"
ENDIF
cNAME := UPPER(ALLTRIM(cNAME))
IF .not. oRsMTP:eof
oRsMTP:MoveFirst()
ENDIF
oRsMTP:Find( "MTRPOOL LIKE '"+cNAME+"%'" )
IF oRsMTP:eof
oRsMTP:MoveFirst()
ENDIF
DEFINE DIALOG oDlg RESOURCE "MTRPSLCT" ;
COLOR "W+/W" ;
TITLE "Motorpool Select" ;
REDEFINE LISTBOX oLBX FIELDS ;
oRsMTP:Fields("MTRPOOL"):Value ;
HEADERS "Motorpool" ;
SIZES 100 ;
ID 111 of oDlg ;
UPDATE
REDEFINE BUTTON oBTN2 ID 113 ;
ACTION ( zPOOLID := oRsMTP:Fields("poolid"):Value, ;
zMTRPOOL := oRsMTP:Fields("MTRPOOL"):Value, ;
oOBJ:Refresh(), ;
oDlg:END() )
REDEFINE BUTTON oBTN2 ID 112 ;
ACTION ( oDlg:END() )
REDEFINE BUTTON oBTN3 ID 114 // ;
* ACTION ( _Mtrpview("A"), ; // mtrpview.prg
* oLBX:ReFresh() )
oLbx:bLogicLen := { || oRsMTP:RecordCount }
oLbx:bGoTop := { || oRsMTP:MoveFirst() }
oLbx:bGoBottom := { || oRsMTP:MoveLast() }
oLbx:bSkip := { | nSkip | Skipper( oRsMTP, nSkip ) }
oLbx:cAlias := "ARRAY"
ACTIVATE DIALOG oDlg ;
ON INIT ( if( (xSUPER = 'Y' .or. xADMIN = 'Y' ), ,oBtn3:Hide() ) )
oRsMTP:CLose()
SysReFresh()
RETURN( .T. )
//-------------------------------
STATIC FUNCTION SKIPPER( oRsx, nSkip )
LOCAL nRec := oRsx:AbsolutePosition
oRsx:Move( nSkip )
IF oRsx:EOF; oRsx:MoveLast(); ENDIF
IF oRsx:BOF; oRsx:MoveFirst(); ENDIF
RETURN( oRsx:AbsolutePosition - nRec )
// end mtrpslct.prg