FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour xBrowse GoLeft() problem
Posts: 82
Joined: Fri Mar 03, 2006 06:26 PM
xBrowse GoLeft() problem
Posted: Fri Sep 19, 2008 02: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

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
xBrowse GoLeft() problem
Posted: Fri Sep 19, 2008 04: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)
#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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
xBrowse GoLeft() problem
Posted: Fri Sep 19, 2008 05: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
xBrowse GoLeft() problem
Posted: Fri Sep 19, 2008 07:12 PM
James,

Using a DBF:
#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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
xBrowse GoLeft() problem
Posted: Fri Sep 19, 2008 07:37 PM
James,

Using a DATABASE object:
#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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
xBrowse GoLeft() problem
Posted: Fri Sep 19, 2008 07:45 PM
Using a DATABASE object and just some columns:
#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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
xBrowse GoLeft() problem
Posted: Fri Sep 19, 2008 08:54 PM

Thanks, Antonio, these are very helpful.

Regards,
James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
xBrowse GoLeft() problem
Posted: 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:

   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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
xBrowse GoLeft() problem
Posted: Sat Sep 20, 2008 01: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

/*
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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
xBrowse GoLeft() problem
Posted: Sat Sep 20, 2008 07:42 AM

James,

Thanks for your example :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
xBrowse GoLeft() problem
Posted: Sat Sep 20, 2008 07:43 AM
There is a little typo here:
   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
Posts: 82
Joined: Fri Mar 03, 2006 06:26 PM
xBrowse GoLeft() problem
Posted: 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

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
xBrowse GoLeft() problem
Posted: Sat Sep 20, 2008 01: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 82
Joined: Fri Mar 03, 2006 06:26 PM
xBrowse GoLeft() problem
Posted: Mon Sep 22, 2008 08: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

Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
xBrowse GoLeft() problem
Posted: 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
Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql

Continue the discussion