xBrowse GoLeft() problem

xBrowse GoLeft() problem

Postby David Williams » Fri Sep 19, 2008 2:49 pm

Hi

I want to edit an array in xBrowse 8.08:

REDEFINE XBROWSE oBrw ID 231 ;
HEADERS "Type", "Tax Base", "Rate", "Amount", "Method" ;
COLSIZES 60, 80, 80, 80, 60 ;
ARRAY aBox47 AUTOCOLS

oBrw:aCols[1]:cHeader := "Type"
oBrw:aCols[1]:cEditPicture := "@K !!!"
oBrw:aCols[1]:nDataStrAlign := AL_LEFT
oBrw:aCols[1]:nHeadStrAlign := AL_CENTER
oBrw:aCols[1]:nEditType := EDIT_GET_BUTTON
oBrw:aCols[1]:bOnPostEdit := {|o,x| if(empty(x), (oBrw:GoDown(), oBrw:GoLeft()), aBox47[ oBrw:nArrayAt, 2 ] := x ) }
oBrw:aCols[1]:bEditBlock := {|| Msginfo("Lookup Tax Code", "TXBrowse power" ) }
oBrw:aCols[1]:bClrEdit := oBrw:bClrStd

oBrw:aCols[2]:cHeader := "Tax Base"
oBrw:aCols[2]:cEditPicture := "@K 99999999999.99"
oBrw:aCols[2]:nDataStrAlign := AL_RIGHT
oBrw:aCols[2]:nHeadStrAlign := AL_RIGHT
oBrw:aCols[2]:nEditType := EDIT_GET
oBrw:aCols[2]:bOnPostEdit := {|o,x| aBox47[ oBrw:nArrayAt, 2 ] := x }
oBrw:aCols[2]:bClrEdit := oBrw:bClrStd

In the bOnPostEdit for column 1, if nothing is entered in first column, I want to move down a row and edit the first column. GoLeft() doesn't seem to move the selected cell left. I have also tried GoLeftMost()

I can do this no problem in TSBrowse with oBrw:aColumns[nCol]:nEditMove := DT_MOVE_NEXT

Can someone help please.

Regards
David
User avatar
David Williams
 
Posts: 82
Joined: Fri Mar 03, 2006 6:26 pm
Location: Ireland

Postby Antonio Linares » Fri Sep 19, 2008 4:29 pm

David,

This is a modified version of fwh\samples\mallorca.prg.

I have included oBrw:GoDown() and oBrw:GoLeft() in the second column, and here it is working fine:

mallorca.prg (modified)
Code: Select all  Expand view
#INCLUDE "FiveWin.ch"
#INCLUDE "XBrowse.ch"

function Main()

   local oWnd, aLin := {}, i, oBar, oBrw

   for i := 1 TO 6
      AAdd( aLin, { i, "Description " + Str( i ), Replicate( Chr( 64 + i ), 2 ) } )
   next

   DEFINE WINDOW oWnd

   DEFINE BUTTONBAR oBar OF oWnd 2007

   DEFINE BUTTON OF oBar RESOURCE "test" ACTION MsgInfo( "Click" )

   DEFINE BUTTON OF oBar RESOURCE "exit" ACTION oWnd:End()

   oBrw := TxBrowse():New( oWnd )
   oBrw:SetArray( aLin )
   oBrw:nColDividerStyle := LINESTYLE_BLACK
   oBrw:nRowDividerStyle := LINESTYLE_BLACK
   oBrw:nMarqueeStyle    := MARQSTYLE_HIGHLCELL

   oBrw:aCols[1]:cHeader      := 'Cod'
//   oBrw:aCols[1]:cEditPicture := '99'
   oBrw:aCols[1]:bClrEdit     := oBrw:bClrStd
   oBrw:aCols[1]:bOnPostEdit  := { | oCol, xVal, nKey | If( nKey == VK_RETURN, aLin[ oBrw:nArrayAt,1] := xVal,) }
   oBrw:aCols[1]:nEditType    := EDIT_GET
   oBrw:aCols[1]:bEditValid   := { | oGet, oCol | Valida( oGet, oCol ) }
   //--
   oBrw:aCols[2]:cHeader      := 'Description'
   oBrw:aCols[2]:bClrEdit     := oBrw:bClrStd
   oBrw:aCols[2]:bOnPostEdit  := { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( aLin[ oBrw:nArrayAt,2] := xVal, oBrw:GoDown(), oBrw:GoLeft() ),) }
   oBrw:aCols[2]:nEditType    := EDIT_GET
   //--
   oBrw:aCols[3]:cHeader      := 'Cd'
   oBrw:aCols[3]:bClrEdit     := oBrw:bClrStd
   oBrw:aCols[3]:bOnPostEdit  := { | oCol, xVal, nKey | If( nKey == VK_RETURN, aLin[ oBrw:nArrayAt, 3 ] := xVal,) }
   oBrw:aCols[3]:nEditType    := EDIT_LISTBOX
   oBrw:aCols[3]:aEditListBound := ;
   oBrw:aCols[3]:aEditListTxt   := { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }

   oBrw:CreateFromCode()
   oBrw:bRClicked = { | nRow, nCol | ShowPopup( nRow, nCol, oBrw, aLin ) }
   oWnd:oClient:=oBrw

   ACTIVATE WINDOW oWnd

RETURN NIL

STATIC FUNCTION Valida( oGet, oCol )

   local nVal := 0

   if oGet:Value() > 6
      MsgAlert( "Must be lower than 7" )
      if MsgGet( "New value", "Enter number between 1 and 6", @nVal )
         if nVal > 0 .and. nVal < 7
            oGet:VarPut( nVal )
            oCol:PostEdit()
            return .T.
          endif
      endif
      return .F.
    endif

return .T.

function ShowPopup( nRow, nCol, oBrw, aLin )

   local oMenu

   MENU oMenu POPUP
      MENUITEM "Add" ACTION ( AAdd( aLin, ;
         { Len( aLin ) + 1 , "New item    " + Str( Len( aLin ) + 1 ), ;
         Replicate( Chr( 64  + Len( aLin ) + 1 ), 2 ) } ), oBrw:Refresh() )
      MENUITEM "Delete" ACTION ( ADel( aLin, oBrw:nArrayAt ), ASize( aLin, Len( aLin ) - 1 ), oBrw:Refresh() )
      MENUITEM "Select 3rd Row" ACTION ( oBrw:GoTop(), oBrw:nArrayAt := 3, oBrw:nRowSel := 3, oBrw:Refresh() )
      MENUITEM "Delete All" ACTION ( ASize( aLin, 0 ), oBrw:Refresh() )
      MENUITEM "Report" ACTION oBrw:Report()
      MENUITEM "Excel"  ACTION oBrw:ToExcel()
   ENDMENU

   ACTIVATE POPUP oMenu WINDOW oBrw AT nRow, nCol

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby James Bott » Fri Sep 19, 2008 5:55 pm

Antonio,

> oBrw:aCols[2]:bOnPostEdit := { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( aLin[ oBrw:nArrayAt,2] := xVal, oBrw:GoDown(), oBrw:GoLeft() ),) }

Can you show us an example using a DBF object and a regular DBF?

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Antonio Linares » Fri Sep 19, 2008 7:12 pm

James,

Using a DBF:
Code: Select all  Expand view
#include "FiveWin.ch"
#include "XBrowse.ch"

function Main()

   local oWnd, oBrw, oCol

   USE Customer

   DEFINE WINDOW oWnd
   
   @ 0, 0 XBROWSE oBrw OF oWnd ALIAS "Customer"
   
   oCol = oBrw:AddCol()
   oCol:bStrData    = { || Customer->First }
   oCol:cHeader     = "First"
   oCol:nEditType   = EDIT_GET
   oCol:bOnPostEdit = { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( Customer->First := xVal, oBrw:GoRight() ),) }

   oCol = oBrw:AddCol()
   oCol:bStrData    = { || Customer->Last }
   oCol:cHeader     = "Last"
   oCol:nEditType   = EDIT_GET
   oCol:bOnPostEdit = { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( Customer->Last := xVal, oBrw:GoDown(), oBrw:GoLeft() ),) }
   
   oBrw:CreateFromCode()
   
   oWnd:oClient = oBrw

   ACTIVATE WINDOW oWnd

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Fri Sep 19, 2008 7:37 pm

James,

Using a DATABASE object:
Code: Select all  Expand view
#include "FiveWin.ch"
#include "XBrowse.ch"

function Main()

   local oWnd, oDbf, oBrw, oCol

   USE Customer
   DATABASE oDbf

   DEFINE WINDOW oWnd
   
   @ 0, 0 XBROWSE oBrw OF oWnd OBJECT oDbf

   oBrw:CreateFromCode()
   
   oBrw:aCols[ 1 ]:nEditType   = EDIT_GET
   oBrw:aCols[ 1 ]:bOnPostEdit = { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( oDbf:First := xVal, oDbf:Save(), oBrw:GoRight() ),) }

   oBrw:aCols[ 2 ]:nEditType   = EDIT_GET
   oBrw:aCols[ 2 ]:bOnPostEdit = { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( oDbf:Last := xVal, oDbf:Save(), oBrw:GoDown(), oBrw:GoLeft() ),) }
   
   oWnd:oClient = oBrw

   ACTIVATE WINDOW oWnd

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Fri Sep 19, 2008 7:45 pm

Using a DATABASE object and just some columns:
Code: Select all  Expand view
#include "FiveWin.ch"
#include "XBrowse.ch"

function Main()

   local oWnd, oDbf, oBrw, oCol

   USE Customer
   DATABASE oDbf

   DEFINE WINDOW oWnd
   
   @ 0, 0 XBROWSE oBrw OF oWnd OBJECT oDbf

   oCol = oBrw:AddCol()
   oCol:cHeader                = "First"
   oCol:bStrData               = { || oDbf:First }     
   oBrw:aCols[ 1 ]:nEditType   = EDIT_GET
   oBrw:aCols[ 1 ]:bOnPostEdit = { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( oDbf:First := xVal, oDbf:Save(), oBrw:GoRight() ),) }

   oCol = oBrw:AddCol()
   oCol:cHeader                = "Last"
   oCol:bStrData               = { || oDbf:Last }     
   oBrw:aCols[ 2 ]:nEditType   = EDIT_GET
   oBrw:aCols[ 2 ]:bOnPostEdit = { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( oDbf:Last := xVal, oDbf:Save(), oBrw:GoDown(), oBrw:GoLeft() ),) }

   oBrw:CreateFromCode()
   
   oWnd:oClient = oBrw

   ACTIVATE WINDOW oWnd

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby James Bott » Fri Sep 19, 2008 8:54 pm

Thanks, Antonio, these are very helpful.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby James Bott » Sat Sep 20, 2008 12:58 am

There is a problem with the movement when editing using the above oDBF example. When you exit the edit (GET) using an up or down arrow key, the new value is lost. Here is a fix:

Code: Select all  Expand view
   oBrw:aCols[ 1 ]:bOnPostEdit = { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( oDbf:First := xVal, oDbf:Save(), oBrw:GoDown() ), (oDBF:First:= xVal, oDbf:Save())) }


Now, if I could just figure out how to trigger the edit mode using any alpha-numeric key instead of the Enter key. Does anyone know how?

If we can solve this we can get xbrowse to act much more like a spreadsheet.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby James Bott » Sat Sep 20, 2008 1:24 am

I found the answer to my own question about alpha-numeric keys triggering the edit-- use oBrw:lFastEdit := .t.

Here is an example of XBrowse that acts like a spreadsheet edit.

Regards,
James

Code: Select all  Expand view
/*
Purpose: XBrowse example with spreadsheet style editing
Note   : Any alpha-numeric key triggers the edit, and up and down arrows exit the edit
         Tested with FWH 8.08

*/

#include "FiveWin.ch"
#include "XBrowse.ch"

function Main()

   local oWnd, oDbf, oBrw, oCol

   USE Customer
   DATABASE oDbf

   DEFINE WINDOW oWnd

   @ 0, 0 XBROWSE oBrw OF oWnd OBJECT oDbf

   oBrw:lFastEdit:=.t.

   oCol = oBrw:AddCol()
   oCol:cHeader                = "First"
   oCol:bStrData               = { || oDbf:First }
   oBrw:aCols[ 1 ]:nEditType   = EDIT_GET
   oBrw:aCols[ 1 ]:bOnPostEdit = { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( oDbf:First := xVal, oDbf:Save(), oBrw:GoDown() ), (oDBF:First:= xVal, oDbf:Save()) ) }

   oCol = oBrw:AddCol()
   oCol:cHeader                = "Last"
   oCol:bStrData               = { || oDbf:Last }
   oBrw:aCols[ 2 ]:nEditType   = EDIT_GET
   oBrw:aCols[ 2 ]:bOnPostEdit = { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( oDbf:Last := xVal, oDbf:Save(), oBrw:GoDown() ),(oDBF:First:= xVal, oDbf:Save()) ) }

   oBrw:CreateFromCode()

   oWnd:oClient = oBrw

   ACTIVATE WINDOW oWnd

return nil
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Antonio Linares » Sat Sep 20, 2008 7:42 am

James,

Thanks for your example :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Sat Sep 20, 2008 7:43 am

There is a little typo here:
Code: Select all  Expand view
   oBrw:aCols[ 2 ]:bOnPostEdit = { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( oDbf:Last := xVal, oDbf:Save(), oBrw:GoDown() ),(oDBF:First:= xVal, oDbf:Save()) ) }

The oDbf:First should be oDbf:Last
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby David Williams » Sat Sep 20, 2008 11:02 am

Antonio

The problem was lFastEdit := .t. :oops:
It appears to override GoLeft()

Thanks for your help.
Also James for invoking further examples, which I found very helpful. :)

Regards
David
User avatar
David Williams
 
Posts: 82
Joined: Fri Mar 03, 2006 6:26 pm
Location: Ireland

Postby James Bott » Sat Sep 20, 2008 1:44 pm

David,

>The problem was lFastEdit := .t.
>It appears to override GoLeft()

I discovered this also. It only happens when the Return key is used to exit the edit (but not when the up or down arrow keys are used in my example). It seems that when lFastEdit is used, there is movement processing AFTER bOnPostEdit by xBrowse. If you are in the first column, GoLeft() has no effect because you are already in the left-most column. Then xBrowse does a GoRight() after your GoLeft(). I think it will take modification of XBrowse to change this behavior.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby David Williams » Mon Sep 22, 2008 8:19 am

James,

<<It seems that when lFastEdit is used, there is movement processing AFTER bOnPostEdit by xBrowse>>

You're right about this.

I need lFastEdit set to .t. to avoid pressing ENTER to enter each cell. However, if I want to remain in a cell when the data is wrong, I have to set lFastEdit to .f. and set it .t. when corrected. I have to do something similar when I need to move left.

Regards,
David
User avatar
David Williams
 
Posts: 82
Joined: Fri Mar 03, 2006 6:26 pm
Location: Ireland

Postby FranciscoA » Wed Oct 15, 2008 12:22 pm

David Williams wrote:James,

<<It seems that when lFastEdit is used, there is movement processing AFTER bOnPostEdit by xBrowse>>

You're right about this.

I need lFastEdit set to .t. to avoid pressing ENTER to enter each cell. However, if I want to remain in a cell when the data is wrong, I have to set lFastEdit to .f. and set it .t. when corrected. I have to do something similar when I need to move left.

Regards,
David


David, can you show us a little example about this?
Thanks, regards.
FranciscoA
User avatar
FranciscoA
 
Posts: 2158
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 69 guests