by shri_fwh » Mon Dec 21, 2009 7:03 am
Hi Nagesh,
I am sorry too late for post the code. I was busy in office project. Please see below source code.
Problem description : Navigation between GET and TXBRowse control.
In the below code first control focus goes to GET object ( cAccountName ) and it moves to TXBRowse Control.
When user select an item and enter Rate value after the control moves to List Box Column (KG,BOX,PCS). Here when user select an item form ListBox column control focus moves to the GET object ( cAccountName ) where as it should moves to next column of the TXBrowse whic 'Quantity' Column.
Thanks
Shridhar
//-----------------------------------------------------------------------------------------------------------------------//
#include 'fivewin.ch'
#include 'xbrowse.ch'
static aItems := { ;
{ 'Floppy', 10 }, ;
{ 'DVD', 100 }, ;
{ 'Web Cam', 650 }, ;
{ 'HeadSet', 150 }, ;
{ 'USB Drive-4', 400 }, ;
{ 'USB Drive-8', 800 } }
//------------------------------------------------------------------//
function Main()
local oDlg, oBrw, oFont
local aBill := { ;
{ 'Floppy', 10,"BOX", 300, .t., 10 }, ;
{ 'DVD', 100,"PCS", 10, .f., 0 } }
local aoGET := array(10)
local aoSAY := array(10)
LOCAL cAccountName := space(30)
SetGetColorFocus()
DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-12
DEFINE DIALOG oDlg SIZE 640,400 PIXEL ;
FONT oFont TITLE 'INVOICE'
@20 , 10 Say aoSAY[1] VAR "Account" PIXEL SIZE 40,10 OF oDlg
@20, 55 GET aoGET[1] VAR cAccountName PICTURE "@!" ;
PIXEL size 150, 9 ;
OF oDlg UPDATE
@ 40,10 XBROWSE oBrw SIZE 300,120 PIXEL OF oDlg ;
COLUMNS 1,2,3,4,5,6 ;
HEADERS 'Item', 'Rate', 'Unit', 'Quantity', 'Dis', 'Discount' ;
PICTURES nil, '9,999.99',nil, '9,99,999', nil, '99.99 %' ;
ARRAY aBill ;
CELL LINES FOOTERS FASTEDIT
AEval( oBrw:aCols, { |oCol| oCol:nEditType := EDIT_GET } )
AEval( oBrw:aCols, { |oCol| oCol:bOnChange := { || oBrw:MakeTotals(), oBrw:RefreshFooters() } } )
// Create a caculated column Amount based on Quantity, Value and Discount
oBrw:Amount := { || oBrw:Quantity:Value * oBrw:Rate:Value * ;
( 1 - oBrw:Discount:Value * 0.01 ) }
WITH OBJECT oBrw:Unit
:nEditType := EDIT_LISTBOX
:aEditListTxt := {"BOX","PCS","KG","LTR"}
END
WITH OBJECT oBrw:Amount
:cEditPicture := '9,99,999.99'
:nTotal := 0 // this and next line tell the browse to auto total
:lTotal := .t.
END
WITH OBJECT oBrw:Discount
:bOnChange := { |oCol,uOldVal| oBrw:Dis:Value := ( oCol:Value != 0 ), ;
oBrw:MakeTotals(), oBrw:RefreshFooters() }
:bEditValid := { |oGet,x| x := oGet:oGet:VarGet(), ( x >= 0 .and. x <= 99 ) }
END
// need to add bEditValid for other numeric columns also
WITH OBJECT oBrw:Dis
:SetCheck()
:bOnChange := { |oCol| If( oCol:Value, nil, ;
( oBrw:Discount:Value := 0, oBrw:MakeTotals(), oBrw:Refresh() ) ) }
END
WITH OBJECT oBrw:Item
:nEditType := EDIT_BUTTON
:AddBmpFile( 'e:\fwh\bitmaps\16x16\find2.bmp' )
:nBtnBmp := 1
:bEditBlock := { || SelectItem( oBrw ) }
END
WITH OBJECT oBrw
:nStretchCol := 1
:bPastEof := { || ExtendRow( oBrw ) }
:bChange := { || BrwChangeRow( oBrw ) }
END
oBrw:MakeTotals()
oBrw:CreateFromCode()
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
return nil
static function ExtendRow( oBrw )
// Pressing down arrow while on the last row creates a new row
// Even after finishing editing of the last row also creates a new row and ready for edit
if oBrw:nArrayAt == Len( oBrw:aArrayData ) .and. ! Empty( ATail( oBrw:aArrayData )[ 1 ] )
AAdd( oBrw:aArrayData, { '', 0, 0, .f., 0 } )
oBrw:GoDown()
oBrw:GoLeftMost()
endif
return nil
static function BrwChangeRow( oBrw )
if Len( oBrw:aArrayData ) > 1 .and. ;
oBrw:nArrayAt < Len( oBrw:aArrayData ) .and. ;
Empty( ATail( oBrw:aArrayData )[ 1 ] )
// If the newly appended row is empty, delete it
ASize( oBrw:aArrayData, Len( oBrw:aArrayData ) - 1 )
oBrw:Refresh()
endif
return nil
//------------- Incremental Browse for selection of Item --------------- //
static function SelectItem( oBillBrw )
local oDlg, oItems, oFont
DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-12
DEFINE DIALOG oDlg SIZE 300,300 PIXEL TITLE 'Select Item' FONT oFont
@ 10,10 XBROWSE oItems SIZE 130,100 PIXEL OF oDlg ;
AUTOCOLS ;
HEADERS 'Item', 'Rate' ;
PICTURES nil, '9,999.99' ;
ARRAY aItems ;
AUTOSORT ; // Xbrowse makes incremental seek blocks only when autosort is true
CELL LINES ;
ON DBLCLICK ( SetValues( oItems, oBillBrw ), oDlg:End(), oBillBrw:SetFocus() )
// Following line is what all is needed for incremental browse
// Rest of the work is done by xbrowse
@ 115,10 SAY oItems:oSeek PROMPT oItems:cSeek ;
SIZE 130,10 PIXEL OF oDlg ;
COLOR CLR_RED,CLR_YELLOW UPDATE
@ 130,055 BUTTON 'Select' SIZE 40,12 PIXEL OF oDlg ;
ACTION ( SetValues( oItems, oBillBrw ), oDlg:End(), oBillBrw:SetFocus() )
@ 130,100 BUTTON 'Cancel' SIZE 40,12 PIXEL OF oDlg ACTION oDlg:End()
oItems:bKeyChar := { |n| If( n == 13, ( SetValues( oItems, oBillBrw ), oDlg:End() ), nil ) }
oItems:nStretchCol := 1
oItems:CreateFromCode()
ACTIVATE DIALOG oDlg CENTERED ON INIT ( oItems:GoTop(), oItems:SetFocus(), .f. )
RELEASE FONT oFont
return nil
static function SetValues( oItems, oBillBrw )
local nAt
nAt := AScan( oBillBrw:aArrayData, { |a| Trim( a[ 1 ] ) == Trim( oItems:Item:Value ) } )
if nAt > 0
oBillBrw:nArrayAt := nAt
oBillBrw:Refresh()
Eval( oBillBrw:bChange )
else
WITH OBJECT oBillBrw
:Item:Value := oItems:Item:Value
:Rate:Value := oItems:Rate:Value
if Empty( :Quantity:Value )
:Quantity:Value := 1
endif
:MakeTotals()
:RefreshCurrent()
:RefreshFooters()
END
endif
return nil
//--------------- End of Incremental Browse for Selection ---------------- //
Thanks
Shridhar
FWH 19.12, BCC 7 32 bit, MariaDB