XBrowse edit only one column

XBrowse edit only one column

Postby James Bott » Tue Jun 18, 2019 12:54 am

How can I edit and limit cursor movement to only one column of an XBrowse?

I searched the forum but couldn't find an answer.
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: XBrowse edit only one column

Postby nageswaragunupudi » Tue Jun 18, 2019 1:05 am

Set oBrw:aCols[ n ]:nEditType := EDIT_GET where nth column is the only column to be edited. By default, nEditType of all other columns is 0.

Then only the nth column can be edited.

If the browse is created with FASTEDIT clause or oBrw:lFastEdit is set to .t., after the user edits this column in one row, the cursor will automatically jump to the same column in the next row, skipping all other columns.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: XBrowse edit only one column

Postby James Bott » Tue Jun 18, 2019 1:42 am

Thanks Nages, I just figured that out before I read your message.

My next problem is how do I reassign the new value to the cell. I am browsing an array of record objects. Here is my code:

Code: Select all  Expand view
@ 0,0 XBROWSE oBrw OF oWnd ;
      FIELDS oBrw:aRow:PLU, oBrw:aRow:DESCRIP, oBrw:aRow:Cost, oBrw:aRow:qtyord, oBrw:aRow:extPrice ;
      HEADERS "PLU", "Description","Cost","Qty","Total" ;
      COLSIZES 50,140,70,70,70 ;
      ARRAY aItems //;
      //COLORS CLR_WHITE, CLR_BLUE
     
      oBrw:nRowHeight       := 25
      //oBrw:nMarqueeStyle    := MARQSTYLE_HIGHLROW
      oBrw:lRecordSelector  := .f.
      oBrw:nStretchCol      := STRETCHCOL_LAST
      oBrw:nRowDividerStyle := LINESTYLE_LIGHTGRAY
      oBrw:nColDividerStyle := LINESTYLE_LIGHTGRAY
     
      oBrw:lFastEdit := .T.
     
      oBrw:CreateFromCode()

      oBrw:aCols[4]:nEditType(1)  // 1 is a GET
      oBrw:aCols[4]:bOnPostEdit:= {|self,uData|  …?  } // Not working yet.
 

It is the last line I can't figure out. I can enter a new value, but I don't know how to save it to the record object.

Ideas?
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: XBrowse edit only one column

Postby nageswaragunupudi » Tue Jun 18, 2019 3:30 am

I understand you want to browse and edit an array of your TRecord() objects. We do not have TRecord class or TData class.
We prepared this sample using TDatabase and TDataRow (now FW_Record) classes of FWH.
First please build and run this program as it is using FWH native classes. Then you may adopt to TData and TRecord classes with suitable modifications.

This program is tested both with FWH1905 and current version.

Code: Select all  Expand view

#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local aItems   := {}
   local oCust, oDlg, oBrw, oFont, n

   oCust    := TDataBase():Open( nil, "CUSTOMER", "DBFCDX", .t. )

   for n := 1 to 10
      oCust:GoTo( n )
      AAdd( aItems, oCust:record() )
   next

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 800,400 PIXEL TRUEPIXEL FONT oFont ;
      TITLE FWVERSION

   @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE aItems ;
      COLUMNS "ID", "First", "City", "Age", "Salary" ;
      HEADERS "ID", "FirstName", "Address", "Age", "Salary" ;
      PICTURES "999" ;
      CELL LINES NOBORDER FASTEDIT

   WITH OBJECT oBrw
      :bClrStd          := { || { CLR_BLACK, GetSysColor( 15 ) } }
      WITH OBJECT :Age
         :nEditType     := EDIT_GET
         :bClrStd       := { || { CLR_BLACK, CLR_WHITE } }
      END
      :bSaveData        := { || oBrw:aRow:Save() } // You may change this for your TRecord class
      :nColSel          := oBrw:oCol( "Age" ):nCreationOrder
      //
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

   // Now, verify that the changes are actually written to the dbf
   oCust:GoTop()
   XBROWSER oCust

   oCust:End()

return nil

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


Notes:
1) Please do not use FIELDS clause. Instead use COLUMNS clause as used in the sample above. XBrowse takes care of assigning the edited values.
2) Do not prepare your own bOnPostEdit. XBrowse, by default, provides the most suitable codeblock for this. Not desirable to override XBrowse's defaults.

Image

Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: XBrowse edit only one column

Postby Silvio.Falconi » Tue Jun 18, 2019 10:35 am

there is an error on FWVERSION
18.05 -------------->19.05
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: XBrowse edit only one column

Postby nageswaragunupudi » Tue Jun 18, 2019 10:41 am

Silvio.Falconi wrote:there is an error on FWVERSION
18.05 -------------->19.05

What is the error?
I built this sample with FWH1805, because I saw that Mr. James Bott is using FWH1805.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: XBrowse edit only one column

Postby Silvio.Falconi » Tue Jun 18, 2019 10:50 am

ah ok
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: XBrowse edit only one column

Postby Silvio.Falconi » Tue Jun 18, 2019 1:05 pm

Nages,
how Manage ( with tdatabase ) two dbf as an Invoice ?
the first for as Master and the second for the Items of Master ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: XBrowse edit only one column

Postby James Bott » Tue Jun 18, 2019 2:59 pm

Nages,

Thanks for the reply, but it appears that I was not clear in my question.

I have an invoice class which contains a line Item list. This list is an array of record objects. I don't want to save the edits when they are made, I will save everything when the entire invoice edit is done.

So, what I am trying to do now is just replace the data in the record buffer with the user edits. The only thing editable is the quantity ordered. I can get into the edit mode, but when I leave the cell the data is lost and the old data reappears. I have tried dozens of ways with no luck. Perhaps this is not possible, and if so can it be done with just a multi-dimensional array?

Regards,
James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: XBrowse edit only one column

Postby nageswaragunupudi » Tue Jun 18, 2019 3:28 pm

Very simple to change.
Please try this modified program
Code: Select all  Expand view
#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local aItems   := {}
   local oCust, oDlg, oBrw, oFont, n

   oCust    := TDataBase():Open( nil, "CUSTOMER", "DBFCDX", .t. )

   for n := 1 to 10
      oCust:GoTo( n )
      AAdd( aItems, oCust:record() )
   next

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 800,600 PIXEL TRUEPIXEL FONT oFont ;
      TITLE FWVERSION

   @  70,20 SAY "EDIT MAIN INVOICE BODY HERE" SIZE 760,24 PIXEL OF oDlg CENTER

   @ 150,20 XBROWSE oBrw SIZE -20,-80 PIXEL OF oDlg ;
      DATASOURCE aItems ;
      COLUMNS "ID", "First", "City", "Age", "Salary" ;
      HEADERS "ID", "FirstName", "Address", "Age", "Salary" ;
      PICTURES "999" ;
      CELL LINES NOBORDER FASTEDIT

   WITH OBJECT oBrw
      :bClrStd          := { || { CLR_BLACK, GetSysColor( 15 ) } }
      WITH OBJECT :Age
         :nEditType     := EDIT_GET
         :bClrStd       := { || { CLR_BLACK, CLR_WHITE } }
      END
      :nColSel          := oBrw:oCol( "Age" ):nCreationOrder
      //
      :CreateFromCode()
   END

   @ 540, 20 BUTTON "SAVE"   SIZE 150,30 PIXEL OF oDlg ;
      ACTION ( AEval( aItems, { |o| o:Save() } ), oDlg:End() )

   @ 540,200 BUTTON "CANCEL" SIZE 150,30 PIXEL OF oDlg ACTION oDlg:End()


   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

   oCust:GoTop()
   XBROWSER oCust

   oCust:End()

return nil

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

Please let me know if this logic works for you or do you need something else.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: XBrowse edit only one column

Postby Silvio.Falconi » Tue Jun 18, 2019 4:27 pm

Nages,
I think that james refers to two dbf, for a sample Master.dbf Items.dbf
the two archives are linked by the invoice number (set scope to)
when the use open ( ord add new) a record of Master , the record must be lock and create an array for the items
the user can modify the array or add new rows
When the user save the procedue must save the record on Master and the Items on Items.dbf ( having the same invoice number)
and the unlock the record (of Master)

this is in theory but in practice how is it done with tdatabase ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: XBrowse edit only one column

Postby nageswaragunupudi » Tue Jun 18, 2019 4:30 pm

Silvio.Falconi wrote:Nages,
I think that james refers to two dbf, for a sample Master.dbf Items.dbf
the two archives are linked by the invoice number (set scope to)
when the use open ( ord add new) a record of Master , the record must be lock and create an array for the items
the user can modify the array or add new rows
When the user save the procedue must save the record on Master and the Items on Items.dbf ( having the same invoice number)
and the unlock the record (of Master)

this is in theory but in practice how is it done with tdatabase ?

I know. But all that he can do and he is taking care of.
It is only the details part he has asked for now.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: XBrowse edit only one column

Postby James Bott » Wed Jun 19, 2019 12:05 am

Nages,

Thanks. It is running here and that was just what I needed. Next I will convert it to my files.

As you said to Silvio, I can handle the rest myself.

Regards,
James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: XBrowse edit only one column

Postby damianodec » Wed Jul 10, 2019 1:46 pm

I'd like to change field Salary (Age * 1.5 / Actual Salary value) after I changed age value, how can I do it?

thank you.
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
User avatar
damianodec
 
Posts: 419
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia

Re: XBrowse edit only one column

Postby nageswaragunupudi » Thu Jul 11, 2019 6:51 am

oBrw:Age:bOnChange := { |oCol, nOldVal| oBrw:Salary:VarPut( oCol:Value * <yourcalculation> ) }
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 38 guests