It'd be easier to understand using a self-contained example that I'm attaching below.
Here's the steps to show you what I mean:
1. Set focus in column Account and press F2. A dialogue-box box simulating a picklist appear, press Yes (this represent user selecting an account code).
2. Now a validation is done and it's determined this particular account code requires getting additional info. Press Yes at the More-Info dialogue box that appear
3. At this point, the focus is back at column Account. I really wanted it to be in the next column if user did key in additional info at step 2 but I don't know how to programmatically do so.
4. Since now user is at column Account, they'd have no choice but press the right arrow key to go to the next column but this would cause the More-Info dialogue box to pops-up again which is really annoying.
Anyone has any idea how to smooth all of these out?
Prg
- Code: Select all Expand view
/**************
Author: Hua
Description: Sample showing how user can invoke a picklist using F2 and
stuff selected value back in the xBrowse's cell
****/
#include "FiveWin.ch"
#include "xbrowse.ch"
static oWnd, aFiledbf
#define LN_ACCN 1
#define LN_CENTRE 3
#define LN_ADDITIONAL 5
function Main()
local oDlg, oBrw
aFiledbf := { {space(5), space(20), space(3), 0.00,""}, ;
{space(5), space(20), space(3), 0.00,""} ;
}
define window oWnd
define dialog oDlg resource "journal" of oWnd
// bof - xBrowse parameters
redefine xbrowse oBrw id 101 of oDlg ;
columns 1, 2, 3, 4 ;
headers "Account", "Description", "Centre", "Amount" ;
pictures "@!",,"@!","999,999.99" ;
array aFiledbf ;
footers fastedit lines cell update ;
oBrw:bKeyDown := {| nKey | if(nKey==VK_F2, CallColPick(oBrw), nil) }
aeval(oBrw:aCols,{|o| o:lAutoSave := .t., o:nEditType := EDIT_GET})
with object oBrw:aCols[LN_ACCN]
:nEditType := EDIT_GET_BUTTON
:addResource( "down" )
:nBtnBmp := 1
:bEditBlock := {|row, col, oCol| picklist("Account", oBrw, LN_ACCN) }
:bEditValid := {|oGet, oCol| ChkAccn(oGet, oCol, oBrw)}
end
with object oBrw:aCols[LN_CENTRE]
:nEditType := EDIT_GET_BUTTON
:addResource( "down" )
:nBtnBmp := 1
:bEditBlock := {|row, col, oCol| picklist("Centre", oBrw, LN_CENTRE) }
:bEditValid := {|oGet, oCol| IsValidCentre(oGet) }
end
// eof - xBrowse parameters
activate dialog oDlg ;
on init oDlg:oClient := oBrw ;
nomodal valid (oWnd:end(), .t.)
activate window oWnd on init (oWnd:resize(), oWnd:center(), oBrw:setFocus()) //maximized
return nil
//----------------------------------------------------------------------
function picklist(cTitle, oBrw, ele)
local oCol := oBrw:SelectedCol()
local xRet // will hold the value selected by user if any
local lSelect := msgyesno("Imagine this is a picklist where user selects" + CRLF +;
cTitle + " code. Proceed as though user make selection?", "Pick your "+cTitle+" code" )
if lSelect
xRet := upper(cTitle) + "1" // hardcoding the return value for illustrations sake
// if user wasn't editing, have to manually stuff the value in
if oCol:oEditGet == nil
oBrw:aArrayData[oBrw:nArrayAt, ele] := xRet
oBrw:drawSelect()
oCol:edit()
oCol:oEditGet:PostMsg(WM_KEYDOWN, VK_RETURN)
else
oCol:oEditGet:varPut(xRet)
oCol:oEditGet:PostMsg(WM_KEYDOWN, VK_RETURN)
lRefocus := .f.
endif
endif
return xRet
//----------------------------------------------------------------------
function CallColPick(oBrw)
// will be called when user presses F2. If we're at column where picklist is available
// eval its bEditBlock which in turn should be calling picklist()
local oCol := oBrw:SelectedCol()
// if we're in correct column, invoke picklist
if oCol:cHeader == "Account" .or. oCol:cHeader == "Centre"
oCol:oBtnElip:PostMsg(FM_CLICK)
endif
return nil
//----------------------------------------------------------------------
function ChkAccn(oGet, oCol, oBrw)
local cTAccn := oGet:value(), lRet := .t.
if trim(cTAccn) == "ACCOUNT1" // we need more info if it's this account
lRet := msgyesno("Needs more info for 'ACCOUNT1'." +CRLF + ;
"Simulate popup appearing and user keyed-in the additional info?","Get more info")
if lRet
oBrw:aArrayData[oBrw:nArrayAt, LN_ADDITIONAL] := 'bla bla'
endif
endif
oBrw:setFocus()
return lRet
//----------------------------------------------------------------------
function IsValidCentre(oGet)
local cCentre := oGet:value(), lRet := .t.
// profit centre validation goes here
return lRet
RC
- Code: Select all Expand view
down BITMAP LOADONCALL MOVEABLE DISCARDABLE
{
'42 4D 06 01 00 00 00 00 00 00 76 00 00 00 28 00'
'00 00 10 00 00 00 12 00 00 00 01 00 04 00 00 00'
'00 00 90 00 00 00 00 00 00 00 00 00 00 00 00 00'
'00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 80'
'00 00 00 80 80 00 80 00 00 00 80 00 80 00 80 80'
'00 00 80 80 80 00 C0 C0 C0 00 00 00 FF 00 00 FF'
'00 00 00 FF FF 00 FF 00 00 00 FF 00 FF 00 FF FF'
'00 00 FF FF FF 00 88 88 88 88 88 88 88 88 88 88'
'88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88'
'88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88'
'00 00 00 08 88 88 88 88 88 88 88 88 88 88 88 88'
'88 80 88 88 88 88 88 88 88 00 08 88 88 88 88 88'
'80 00 00 88 88 88 88 88 00 00 00 08 88 88 88 88'
'88 00 08 88 88 88 88 88 88 00 08 88 88 88 88 88'
'88 00 08 88 88 88 88 88 88 88 88 88 88 88 88 88'
'88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88'
'88 88 88 88 88 88'
}
journal DIALOG 0, 0, 250, 115
STYLE DS_3DLOOK | WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN
CAPTION ""
FONT 10, "System"
{
CONTROL "", 101, "TXBrowse", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP, 8, 4, 236, 104
}