Edit cell IN xBrowse for nEditType EDIT_GET_BUTTON

Post Reply
User avatar
ralph
Posts: 79
Joined: Fri Nov 18, 2005 11:15 pm
Location: Lima - PERU

Edit cell IN xBrowse for nEditType EDIT_GET_BUTTON

Post by ralph »

[*]Dear master Nages, a few questions:

Code: Select all | Expand

  ...
   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.

Image

Here is my test code

Code: Select all | Expand

#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 5.5, BCC 7.3
User avatar
nageswaragunupudi
Posts: 10691
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Edit cell IN xBrowse for nEditType EDIT_GET_BUTTON

Post by nageswaragunupudi »

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: Select all | Expand

   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: Select all | Expand

   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
User avatar
nageswaragunupudi
Posts: 10691
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Edit cell IN xBrowse for nEditType EDIT_GET_BUTTON

Post by nageswaragunupudi »

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
User avatar
ralph
Posts: 79
Joined: Fri Nov 18, 2005 11:15 pm
Location: Lima - PERU

Re: Edit cell IN xBrowse for nEditType EDIT_GET_BUTTON

Post by ralph »

nageswaragunupudi wrote:
1) when the F2 key is pressed the cell is edited even if :bEditWhen is FALSE
Please modify this like this:

Code: Select all | Expand

   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 5.5, BCC 7.3
User avatar
ralph
Posts: 79
Joined: Fri Nov 18, 2005 11:15 pm
Location: Lima - PERU

Re: Edit cell IN xBrowse for nEditType EDIT_GET_BUTTON

Post by ralph »

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 5.5, BCC 7.3
User avatar
ralph
Posts: 79
Joined: Fri Nov 18, 2005 11:15 pm
Location: Lima - PERU

Re: Edit cell IN xBrowse for nEditType EDIT_GET_BUTTON

Post by ralph »

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: Select all | Expand

   //----------------------------------------------------------------------------//
   // PAINT BUTTON
   //----------------------------------------------------------------------------//

   if ::nEditType > 1 .and. ::nEditType < EDIT_DATE
      if lSelected 
         ::PaintCellBtn( hDC, oBtnRect, aColors )
      endif
   endif
 
with this code:

Code: Select all | Expand

   //----------------------------------------------------------------------------//
   // 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 5.5, BCC 7.3
Post Reply