Anybody have sample source of having a combobox in a column on a TCBrowse.
Where the user could simply change the value of the combobox just by clicking on it.
I haven't even tried, I don't know where to start.
Thanks,
#include "Fivewin.ch"
#include "TCBrowse.ch"
FUNCTION MAIN()
LOCAL oDlg, oBrw
SET CENTURY ON
SET DATE BRITISH
IF !FILE( "TESTEDCO.DBF" )
DBCREATE( "TESTEDCO", { { "CARATTERE", "C", 30, 0 },;
{ "NUMERO", "N", 10, 2 },;
{ "DATA", "D", 8, 0 },;
{ "MEMO", "M", 10, 0 } } )
USE TESTEDCO
APPEND BLANK
APPEND BLANK
CLOSE
ENDIF
USE TESTEDCO
DEFINE DIALOG oDlg SIZE 800, 600
@ 0, 0 BROWSE oBrw
oBrw:bLogicLen = { || ( oBrw:cAlias ) -> ( OrdKeyCount() ) }
oBrw:bLDblClick = { || Modifica( oBrw ) }
oBrw:bKeyDown = { | nKey | If( nKey = VK_RETURN, Modifica( oBrw ), ) }
ADD COLUMN TO oBrw;
DATA TESTEDCO -> carattere;
HEADER "CARATTERE";
SIZE 200
ADD COLUMN TO oBrw;
DATA TESTEDCO -> numero;
HEADER "NUMERO";
PICTURE "@EZ 9,999,999.99";
SIZE 100 RIGHT
ADD COLUMN TO oBrw;
DATA TESTEDCO -> data;
HEADER "DATA";
SIZE 100
ADD COLUMN TO oBrw;
DATA STRTRAN( TESTEDCO -> memo, CRLF, " " );
HEADER "MEMO";
SIZE 100
// ADD COLUMN TO oBrw
oBrw:lCellStyle = .T.
ACTIVATE DIALOG oDlg;
ON INIT oDlg:SetControl( oBrw );
CENTER
CLOSE
RETURN NIL
STATIC FUNCTION MODIFICA( oBrw )
LOCAL nCol := oBrw:nColAct
LOCAL xVar := EVAL( oBrw:aColumns[ nCol ]:bData )
LOCAL xRes
IF xVar = NIL; RETURN NIL; ENDIF
IF nCol = 4
xVar = FIELDGET( 4 )
IF EDITMEMO( oBrw, @xVar )
IF RLOCK()
FIELDPUT( 4, xVar )
oBrw:Refresh( .F. )
ENDIF
ENDIF
RETURN NIL
ENDIF
IF nCol = 1
// IF EDITCOL( oBrw, nCol, 250, @xVar, , CLR_WHITE, CLR_GREEN )
// IF EDITCOL( oBrw, nCol, , @xVar, "Init", CLR_WHITE, CLR_GREEN )
xRes = EDITCOL( oBrw, nCol, , @xVar, , CLR_WHITE, CLR_GREEN, { "Pippo", "Pluto", "Paperino" } )
// xRes = EDITCOL( oBrw, nCol, , @xVar, , CLR_WHITE, CLR_GREEN, , { || MsgInfo( "bAction1" ) }, { || MsgInfo( "bAction2" ) } )
IF VALTYPE( xRes ) = "B"
EVAL( xRes )
ELSE
IF RLOCK()
FIELDPUT( nCol, xVar )
oBrw:Refresh( .F. )
ENDIF
ENDIF
ELSE
IF EDITCOL( oBrw, nCol, , @xVar, , CLR_WHITE, CLR_GREEN )
IF RLOCK()
FIELDPUT( nCol, xVar )
oBrw:Refresh( .F. )
ENDIF
ENDIF
ENDIF
RETURN NIL
STATIC FUNCTION EDITCOL( oBrw, nCol, nWidth, xVar, cInit, nClrText, nClrBack, aList, bAction1, bAction2 )
LOCAL oDlg, oGet, oCbx, oBtn1, oBtn2
LOCAL cTyp := VALTYPE( xVar )
LOCAL cPic := oBrw:aColumns[ nCol ]:cPicture
LOCAL nAli := oBrw:aColumns[ nCol ]:nAlign
LOCAL nStartCol := 0
LOCAL aDim
LOCAL xRes := .F.
LOCAL xTmp := xVar
LOCAL lClose := .F.
LOCAL i
IF oBrw:nFreeze > 0
FOR i = 1 TO MIN( oBrw:nFreeze, nCol - 1 )
nStartCol += oBrw:GetColSizes()[ i ]
NEXT
ENDIF
FOR i = oBrw:nColPos TO nCol - 1
nStartCol += oBrw:aColSizes[ i ]
NEXT
aDim = ATCBRWPOSRECT( oBrw:hWnd, oBrw:nRowPos, nStartCol, oBrw:aColSizes[ nCol ], IF( oBrw:oFont != NIL, oBrw:oFont:hFont, 0 ) )
DEFINE DIALOG oDlg;
STYLE WS_POPUP
oDlg:bLostFocus = { || oDlg:End() }
DO CASE
CASE !EMPTY( aList )
@ 0, 0 COMBOBOX oCbx VAR xTmp;
ITEMS aList;
ON CHANGE ( oCbx:Close(), xRes := .T., oDlg:End() )
CASE cTyp = "C" .OR. cTyp = "D"
@ 0, 0 GET oGet VAR xTmp;
COLOR nClrText, nClrBack;
PICTURE cPic
oGet:nStyle = NAND( oGet:nStyle, NNOT( WS_BORDER ) )
oGet:bKeyDown = { | nKey | If( nKey = VK_RETURN, ( oGet:Assign(), xRes := .T., oDlg:End() ), ) }
CASE cTyp = "N"
@ 0, 0 GET oGet VAR xTmp;
COLOR nClrText, nClrBack;
PICTURE STRTRAN( cPic, ",", "" );
RIGHT
oGet:nStyle = NAND( oGet:nStyle, NNOT( WS_BORDER ) )
oGet:bKeyDown = { | nKey | If( nKey = VK_RETURN, ( oGet:Assign(), xRes := .T., oDlg:End() ), ) }
ENDCASE
IF oGet != NIL .AND. !EMPTY( cInit )
oDlg:bStart = { || PostString( oGet, cInit ) }
ENDIF
IF bAction1 != NIL
@ 0, 0 BTNBMP oBtn1;
FILE "EDITCOL1.BMP";
// NOBORDER
oBtn1:bAction = { || xRes := bAction1, oDlg:End() }
oBtn1:cTooltip = "Questo è il tooltip 1"
ENDIF
IF bAction2 != NIL
@ 0, 0 BTNBMP oBtn2;
FILE "EDITCOL2.BMP";
// NOBORDER
oBtn2:bAction = { || xRes := bAction2, oDlg:End() }
oBtn2:cTooltip = "Questo è il tooltip 2"
ENDIF
ACTIVATE DIALOG oDlg;
ON INIT DLGADJUST( oDlg, oGet, oCbx, oBtn1, oBtn2, nWidth, aDim, cTyp );
VALID lClose := .T.;
NOMODAL
STOPUNTIL( { || lClose } )
IF VALTYPE( xRes ) != "B"
IF xTmp = xVar; xRes = .F.; ENDIF
xVar = xTmp
ENDIF
oBrw:SetFocus()
RETURN xRes
STATIC FUNCTION POSTSTRING( oGet, cString )
LOCAL i
FOR i = 1 TO LEN( cString )
POSTMESSAGE( oGet:hWnd, WM_CHAR, ASC( SUBSTR( cString, i, 1 ) ) )
NEXT
RETURN NIL
STATIC FUNCTION DLGADJUST( oDlg, oGet, oCbx, oBtn1, oBtn2, nWidth, aDim, cType )
DEFAULT nWidth := aDim[ 4 ] - aDim[ 2 ]
IF oCbx != NIL
oDlg:Move( aDim[ 1 ] + 1, aDim[ 2 ] + 1, nWidth + 2, aDim[ 3 ] - aDim[ 1 ] + 2 )
ELSEIF cType = "C" .OR. cType = "D"
oDlg:Move( aDim[ 1 ] + 2, aDim[ 2 ] + 3, nWidth - 2, aDim[ 3 ] - aDim[ 1 ] - 1 )
ELSEIF cType = "N"
oDlg:Move( aDim[ 1 ] + 2, aDim[ 2 ] + 2, nWidth - 1, aDim[ 3 ] - aDim[ 1 ] - 1 )
ENDIF
IF oBtn1 != NIL .AND. oBtn2 != NIL
nWidth -= 33
ELSEIF oBtn1 != NIL .OR. oBtn2 != NIL
nWidth -= 17
ENDIF
IF oGet != NIL
oGet:Move( 0, 0, nWidth, aDim[ 3 ] - aDim[ 1 ] )
ENDIF
IF oCbx != NIL
oCbx:Move( -3, -1, nWidth + 4, aDim[ 3 ] - aDim[ 1 ] )
ENDIF
IF oBtn1 != NIL .AND. oBtn2 != NIL
oBtn1:Move( -1, aDim[ 4 ] - aDim[ 2 ] - 33, 16, 16 )
ENDIF
IF oBtn1 != NIL .AND. oBtn2 = NIL
oBtn1:Move( -1, aDim[ 4 ] - aDim[ 2 ] - 17, 16, 16 )
ENDIF
IF oBtn2 != NIL
oBtn2:Move( -1, aDim[ 4 ] - aDim[ 2 ] - 17, 16, 16 )
ENDIF
RETURN NIL
STATIC FUNCTION EDITMEMO( oBrw, cVar )
LOCAL oDlg, oGet
LOCAL lMod := .T.
LOCAL cTmp := cVar
DEFINE DIALOG oDlg;
SIZE 800, 600
@ 0, 0 GET oGet VAR cTmp MEMO
@ 15.5, 2 BUTTON "&Conferma";
ACTION oDlg:End( IDOK )
@ 15.5, 12 BUTTON "&Annulla";
ACTION oDlg:End()
oDlg:bStart = { || oGet:SetPos( 0 ) }
ACTIVATE DIALOG oDlg;
ON INIT MEMOADJUST( oDlg, oGet );
CENTER
IF oDlg:nResult = IDCANCEL; RETURN .F.; ENDIF
IF cTmp == cVar; lMod = .F.; ENDIF
cVar = cTmp
oBrw:SetFocus()
RETURN lMod
STATIC FUNCTION MEMOADJUST( oDlg, oGet )
oGet:Move( 0, 0, oDlg:nWidth() - 20, oDlg:nHeight() - 100 )
RETURN NIL
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 78 guests