FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour [xBrowse] - Implementing picklist
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM

[xBrowse] - Implementing picklist

Posted: Fri Dec 04, 2009 02:21 AM
Basically what I want to do is bypass the validation done in current column and set focus to the next column.

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 (fw): Select all Collapse
/**************
  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 (fw): Select all Collapse
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
}
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: [xBrowse] - Implementing picklist

Posted: Fri Dec 04, 2009 03:21 AM

Does it work if you call oBrw:GoRight() ?

Regards



G. N. Rao.

Hyderabad, India
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM

Re: [xBrowse] - Implementing picklist

Posted: Fri Dec 04, 2009 04:22 AM

I did give that a try but it will still invoke :bEditValid

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: [xBrowse] - Implementing picklist

Posted: Fri Dec 04, 2009 04:26 AM

bEditValid will be invoked. You need to code bEditValid codeblock to be aware of what you need to do.

Regards



G. N. Rao.

Hyderabad, India
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM

Re: [xBrowse] - Implementing picklist

Posted: Fri Dec 04, 2009 04:32 AM

Ok, thanks Rao. I'll sleep on it for a while

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM

Re: [xBrowse] - Implementing picklist

Posted: Fri Dec 04, 2009 05:29 PM
Hua,

Try something like:

Code (fw): Select all Collapse
 :bEditValid := {|oGet, oCol| if(ChkAccn(oGet, oCol, oBrw), (oBrw:goRight(),.t.),.f.) }


James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM

Re: [xBrowse] - Implementing picklist

Posted: Mon Dec 07, 2009 03:03 AM
Thanks for the reply James but my problem was my 'More-Info' dialogue box got executed twice because I placed it in :bEditValid.

Nevertheless, this is what I've done to solve it:
Code (fw): Select all Collapse
function main()
   .
   oBrw:aCols[LN_ACCN]:bEditWhen := {|oCol| lValidated := .f., .t.} 
   oBrw:aCols[LN_ACCN]:bEditValid  := {|oGet, oCol| ChkAccn(oGet, oCol, oBrw, @lValidated)}
   .
return nil
//------------------------------------------------------------------------------------------------------------
function ChkAccn(oGet, oCol, oBrw, lValidated)
  local cTAccn := oGet:value(), lRet := .t.
  if lValidated
     return .t.
  endif
  .
  .
  if lRet
     lValidated := .t.
     oBrw:GoRight()
  endif
return lRet
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour

Continue the discussion