DEFINE WINDOW oWnd
oBrw := TXBrowse():New( oWnd )
oBrw:SetADO( oRs ) // oRs is your record set
oBrw:CreateFromCode()
oWnd:oClient := oBrw
ACTIVATE WINOW oWnd
oCol := oBrw:AddCol()
oCol:bStrData := { || If( oRs:RecordCount() > 0, oRs:Field(0):Value, space(10) ) }
oCol:cHeader := "Col-1"
// after defining all the columns
oBrw:SetADO( oRs )
// rest of the code
DEFINE DIALOG oDlg SIZE 640,340 PIXEL
@ 10,10 XBROWSE oBrw ;
FIELDS ;
If( oRs:Eof, Space(20), oRs:Fields("First"):Value ), ;
If( oRs:Eof, Space(30), oRs:Fields("Second"):Value ) ;
HEADERS ;
"First", "Second" ;
OF oDlg SIZE 300,150 PIXEL
oBrw:SetADO( oRs )
oBrw:CreateFromCode()
ACTIVATE DIALOG oDlg CENTERED
DEFINE DIALOG oDlg SIZE 640,340 PIXEL
@ 10,10 XBROWSE oBrw ;
OF oDlg SIZE 300,150 PIXEL
for n := 0 to oRs:Fields:Count() - 1
xbrAdoSetField( oBrw, oRs, n )
next
oBrw:SetADO( oRs )
oBrw:CreateFromCode()
ACTIVATE DIALOG oDlg CENTERED
return nil
//-------------------------------------
function xbrAdoSetField( oBrw, oRs, cnFld )
local oCol := oBrw:AddCol()
local nwidth := oRs:Fields( cnFld ):DefinedSize
WITH OBJECT oCol
:cHeader := oRs:Fields(cnFld):Name
:bStrData := { || If( oRs:Eof, Space( nWidth ), cValtoChar( oRs:Fields( cnFld ):Value ) ) }
END
return oCol
oRsPro:CursorLocation := adUseClient
oRsPro:LockType := adLockOptimistic
oRsPro:CursorType := adOpenDynamic
oRsPro:Source := "SELECT * FROM proyecto ORDER BY PRO_PRO"
oRsPro:ActiveConnection(oCnx)
********************
*Catalogo de Medidas
********************
PROC pMedida()
LOCAL aCol:={0,0,0}
STATIC aArrayVars:= {"m_medida"}
#xtranslate vOrden => aArrayVars\[1\]
oLamcla:oC1vg1:=space(100)
oVar := "SELECT * from "+oLamcla:tMedi+" ORDER BY "+alltrim(vOrden)
TRY
oLamcla:oRsMedida := CreateObject("ADODB.Recordset")
CATCH oError
MsgStop( "No se ha podido crear el RECORDSET !","Error de Datos" )
END
oLamcla:oRsMedida:CursorLocation := adUseClient //adUseServer
oLamcla:oRsMedida:LockType := adLockOptimistic
oLamcla:oRsMedida:CursorType := adOpenKeyset
oLamcla:oRsMedida:Source := oVar
oLamcla:oRsMedida:ActiveConnection( oLamcla:oServer )
TRY
oLamcla:oRsMedida:Open()
CATCH oError
MsgStop( "No se ha podido ejecutar el comando !", "Error de Datos" )
END
DEFINE BRUSH oFondo FILE ".\res\res_403.BMP"
DEFINE DIALOG oCuadro RESOURCE "orMedida" ICON "#8001" TRANSPARENT BRUSH oFondo
REDEFINE BUTTONBMP Btn_Limp ID 4003 OF oCuadro BITMAP "Blimpi2" TOOLTIP oLamcla:mTfil //ACTION pValiMed()
//REDEFINE BTNBMP Btn_Limp ID 4010 OF oCuadro RESOURCE "BLimpi2" TOOLTIP oLamcla:mTfil NOBORDER UPDATE //ACTION (oC1vg1:=space(100),pArMedi())
REDEFINE GET oC1og1 VAR oLamcla:oC1vg1 ID 4002 OF oCuadro UPDATE //VALID(pBusMed(),.T.)
oBrw := TXBrowse():New( oCuadro )
oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW
oBrw:nColDividerStyle := LINESTYLE_RAISED
oBrw:nHeaderLines := 1
oBrw:lColDividerComplete := .t.
oBrw:lRecordSelector := .t.
oBrw:bClrSel := {|| { CLR_BLACK,oLamcla:cClr7 } }
oBrw:bClrStd := {|| IF( (oLamcla:oRsMedida:AbsolutePosition()%2)==0,{CLR_BLACK,oLamcla:cClr2},{CLR_BLACK,oLamcla:cClr1} ) }
oBrw:bClrSelFocus := {|| { CLR_WHITE,RGB(147,160,112) } }
aCol[ 1] := oBrw:AddCol()
aCol[ 1]:bStrData := { || If( oLamcla:oRsMedida:Eof, Space( nWidth ), cValtoChar( oLamcla:oRsMedida:Fields( "m_medida" ):Value ) ) }
aCol[ 1]:cHeader := "Codigo"
aCol[ 1]:nHeadStrAlign := AL_LEFT
aCol[ 1]:nDataStrAlign := AL_LEFT
aCol[ 1]:nWidth := 80
aCol[ 2] := oBrw:AddCol()
aCol[ 2]:bStrData := { || If( oLamcla:oRsMedida:Eof, Space( nWidth ), cValtoChar( oLamcla:oRsMedida:Fields( "m_nombre" ):Value ) ) }
aCol[ 2]:cHeader := "Nombre"
aCol[ 2]:nHeadStrAlign := AL_LEFT
aCol[ 2]:nDataStrAlign := AL_LEFT
aCol[ 2]:nWidth := 225
aCol[ 3] := oBrw:AddCol()
aCol[ 3]:bStrData := { || If( oLamcla:oRsMedida:Eof, Space( nWidth ), cValtoChar( oLamcla:oRsMedida:Fields( "m_siglas" ):Value ) ) }
aCol[ 3]:cHeader := "Siglas"
aCol[ 3]:nHeadStrAlign := AL_LEFT
aCol[ 3]:nDataStrAlign := AL_LEFT
aCol[ 3]:nWidth := 225
oBrw:SetADO( oLamcla:oRsMedida )
oBrw:CreateFromResource( 102 )
oCuadro:cTitle := "Tabla de Medidas"
ACTIVATE DIALOG oCuadro On Init (Centra( oCuadro ),oCuadro:refresh(),BarraMed( oCuadro )) CENTERED
oLamcla:oRsMedida:Close()
oBrw:bGoTop := { || If( oRs:RecordCount() > 0, oRs:MoveFirst(), ) }
oBrw:bGoBottom := { || If( oRs:RecordCount() > 0, oRs:MoveLast(), ) }
oBrw:bSkip := { | n | If( oRs:RecordCount == 0, 0, AdoSkip( oRs, If( n == nil, 1, n ) ) ) }
oBrw:bBof := { || oRs:Bof }
oBrw:bEof := { || oRs:Eof }
oBrw:bBookMark := { | uBm | If( If( oRs:RecordCount() == 0, 0, If( uBm == nil, oRs:BookMark, oRs:BookMark := uBm ) ) }
oBrw:bKeyNo := { | n | If( oRs:RecordCount == 0, 0, If( n == nil, oRs:AbsolutePosition, oRs:AbsolutePosition := n ) ) }
oBrw:bKeyCount := { || oRs:RecordCount()}
nageswaragunupudi wrote:Here is a more generic code :
- Code: Select all Expand view
//-------------------------------------
function xbrAdoSetField( oBrw, oRs, cnFld )
local oCol := oBrw:AddCol()
local nwidth := oRs:Fields( cnFld ):DefinedSize
WITH OBJECT oCol
:cHeader := oRs:Fields(cnFld):Name
:bStrData := { || If( oRs:Eof, Space( nWidth ), cValtoChar( oRs:Fields( cnFld ):Value ) ) }
END
return oCol
This code is tested and will work
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 48 guests