FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Edit cell IN xBrowse for nEditType EDIT_GET_BUTTON
Posts: 92
Joined: Fri Nov 18, 2005 11:15 PM
Edit cell IN xBrowse for nEditType EDIT_GET_BUTTON
Posted: Thu Oct 17, 2024 08:51 PM
[*]Dear master Nages, a few questions:
Code (fw): Select all Collapse
  ...
   WITH OBJECT oBrw
      :nEditTypes    := EDIT_GET
      :lFastEdit := .t.
      :lF2KeyToEdit := .t.
      :bPastEof   := { || iif(!empty(field->codprd),dbappend(), ), oBrw:RefreshCurrent() }
      WITH OBJECT :aCols[ 1 ]
         :nEditType  := EDIT_GET_BUTTON
         :nBtnBmp    := :AddBitmap( "EDIT" )
         :bEditBlock := { | nRow, nCol, oCol, nKey | MsgInfo( "edit" ), nil }
         :bEditWhen   := { || empty(field->CODPRD) }
      END
      :CreateFromCode()
   END
...
1) when the F2 key is pressed the cell is edited even if :bEditWhen is FALSE
2) Is it posible to trigger the :bEditBlock when F2 is pressed and only when the cell is editable ?
3) Is it possible to show the bitmap in a column ONLY when the cell is editable ?
In my sample, the field is only editable when i add a new row and field->codprd is empty.



Here is my test code
Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "xbrowse.ch"

static oWnd

//----------------------------------------------------------------------------//

function Main()
   local oBrw, oCol, n
   local nFor, aStru, tmpfile

   REQUEST DBFCDX
   rddsetdefault( "DBFCDX" )

   DEFINE WINDOW oWnd FROM 1, 1 TO 20,90
   aStru := {}
   aadd(aStru, { "CODPRD", "C", 20, 0 })
   aadd(aStru, { "NOMPRD", "C", 60,0 })
   aadd(aStru, { "IMPORT", "N", 12,2 })

   tmpfile := cTempFile("c:\temp",".dbf")
   dbcreate(tmpfile, aStru)
   USE (tmpfile) alias "TEMP" EXCL NEW
   for n := 1 to 5
      dbAppend()
      FIELD->CODPRD     := "P" + padl( n , 2,'0' )
      FIELD->NOMPRD     := {'ONE','TWO','THREE','FOUR','FIVE'}[ HB_RandomInt( 1, 5 ) ]
      FIELD->IMPORT     := HB_RandomInt( 60, 9000 )
   next
   dbgotop()

   @ 1,0 XBROWSE oBrw OF oWnd ALIAS "TEMP" ;
      COLUMNS "codprd","nomprd","import" ;
      SIZES 100,300,100 ;
      CELL LINES NOBORDER

   WITH OBJECT oBrw
      :nEditTypes    := EDIT_GET
      :lFastEdit := .t.
      :lF2KeyToEdit := .t.
      :bPastEof   := { || iif(!empty(field->codprd),dbappend(), ), oBrw:RefreshCurrent() }
      WITH OBJECT :aCols[ 1 ]
         :nEditType  := EDIT_GET_BUTTON
         :nBtnBmp    := :AddBitmap( "EDIT" )
         :bEditBlock := { | nRow, nCol, oCol, nKey | MsgInfo( "edit" ), nil }
         :bEditWhen   := { || empty(field->CODPRD) }
      END
      :CreateFromCode()
   END

   oWnd:oClient := oBrw

   ACTIVATE WINDOW oWnd ON INIT oBrw:setfocus()

return nil


Thanks for your attention
Ralph del Castillo

Lima PERU

Fwh 24.07, xHb123_10193, MySQL 8.x, BCC 7.3
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Edit cell IN xBrowse for nEditType EDIT_GET_BUTTON
Posted: Fri Oct 18, 2024 09:59 AM
1) when the F2 key is pressed the cell is edited even if :bEditWhen is FALSE
Yes. This is a bug in xbrowse.prg, which has been overlooked for many years.
Thanks for pointing this out.

Can you apply this fix in xbrowse.prg and confirm if this working well.

Please locate these lines in METHOD KeyDown(...) in XBrowse.prg:
Code (fw): Select all Collapse
   case nKey == VK_F2 .and. ::lF2KeyToEdit .and. ! ::lReadOnly
        if ! ::lEditMode
            WITH OBJECT ::SelectedCol()
               if ! :lReadOnly
                  :Edit()
               endif
            END
        endif
Please modify this like this:
Code (fw): Select all Collapse
   case nKey == VK_F2 .and. ::lF2KeyToEdit .and. ! ::lReadOnly
        if ! ::lEditMode
            WITH OBJECT ::SelectedCol()
               if :lEditable //! :lReadOnly
                  :Edit()
               endif
            END
        endif
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Edit cell IN xBrowse for nEditType EDIT_GET_BUTTON
Posted: Fri Oct 18, 2024 10:18 AM
2) Is it posible to trigger the :bEditBlock when F2 is pressed and only when the cell is editable ?
if nEditType is EDIT_GET_BUTTON, then when F2 is pressed, the Get is invoked.
if nEditType is EDIT_BUTTON, then when F2 is pressed the ButtonAction is invoked.
For your requirement use EDIT_BUTTON. Not EDIT_GET_BUTTON.
Regards



G. N. Rao.

Hyderabad, India
Posts: 92
Joined: Fri Nov 18, 2005 11:15 PM
Re: Edit cell IN xBrowse for nEditType EDIT_GET_BUTTON
Posted: Fri Oct 18, 2024 03:25 PM
nageswaragunupudi wrote:
1) when the F2 key is pressed the cell is edited even if :bEditWhen is FALSE
Please modify this like this:
Code (fw): Select all Collapse
   case nKey == VK_F2 .and. ::lF2KeyToEdit .and. ! ::lReadOnly
        if ! ::lEditMode
            WITH OBJECT ::SelectedCol()
               if :lEditable //! :lReadOnly
                  :Edit()
               endif
            END
        endif
Yes, it works perfect. Thanks!
Ralph del Castillo

Lima PERU

Fwh 24.07, xHb123_10193, MySQL 8.x, BCC 7.3
Posts: 92
Joined: Fri Nov 18, 2005 11:15 PM
Re: Edit cell IN xBrowse for nEditType EDIT_GET_BUTTON
Posted: Fri Oct 18, 2024 03:41 PM
nageswaragunupudi wrote:
2) Is it posible to trigger the :bEditBlock when F2 is pressed and only when the cell is editable ?
if nEditType is EDIT_GET_BUTTON, then when F2 is pressed, the Get is invoked.
if nEditType is EDIT_BUTTON, then when F2 is pressed the ButtonAction is invoked.
For your requirement use EDIT_BUTTON. Not EDIT_GET_BUTTON.
The user use to write the product code manually (or scan a barcode), that is why i need to use EDIT_GET_BUTTON
If the user want to search a similar product, then can pick the button to display a list, but it would be very useful if he could use the keyboard (F2) also.
I need to replicate this behaviour in the new xBrowse.

Any suggestion is welcomed
Ralph del Castillo

Lima PERU

Fwh 24.07, xHb123_10193, MySQL 8.x, BCC 7.3
Posts: 92
Joined: Fri Nov 18, 2005 11:15 PM
Re: Edit cell IN xBrowse for nEditType EDIT_GET_BUTTON
Posted: Fri Oct 18, 2024 06:19 PM
ralph wrote: 3) Is it possible to show the bitmap in a column ONLY when the cell is editable ?
In my sample, the field is only editable when i add a new row and field->codprd is empty.
i modified the Method PaintCell() of the class this way:
original code:
Code (fw): Select all Collapse
   //----------------------------------------------------------------------------//
   // PAINT BUTTON
   //----------------------------------------------------------------------------//

   if ::nEditType > 1 .and. ::nEditType < EDIT_DATE
      if lSelected 
         ::PaintCellBtn( hDC, oBtnRect, aColors )
      endif
   endif
with this code:
Code (fw): Select all Collapse
   //----------------------------------------------------------------------------//
   // PAINT BUTTON
   //----------------------------------------------------------------------------//

   if ::nEditType > 1 .and. ::nEditType < EDIT_DATE
      if lSelected .and. ::lEditable  //RDC
         ::PaintCellBtn( hDC, oBtnRect, aColors )
      endif
   endif
It works fine!.
Ralph del Castillo

Lima PERU

Fwh 24.07, xHb123_10193, MySQL 8.x, BCC 7.3

Continue the discussion