xBrowse edit_get cell based on table value at runtime

xBrowse edit_get cell based on table value at runtime

Postby Rick Lipkin » Thu Apr 26, 2012 9:57 pm

To All

Again, I am struggling to program xBrowse to be able to edit a cell based on a field in a table. Using this snipit of code I am able to paint the Listbox and the columns edit correctly based on the field 'LockedDown' but when you append a new record the columns that were created as not editable should now be editable based on the If statement and the nEditType code block.

Here is the snipit of code .. again, appending a new record flagging the 'LockedDown' field does not change the nEditType block at runtime ..

As you can see in the AddNewRecord function .. I am refreshing the browse and setting the new appended field 'LockedDown' to .f. .. The blue color designates the column was not editable when the browse was painted ..

Rick Lipkin

Code: Select all  Expand view

// row number
 oLbxB:aCols[1]:nEditType := EDIT_NONE

// qty
oLbxB:aCols[2]:nEditType := If( oRsDetail:fields("LockedDown"):Value = .t., EDIT_NONE, EDIT_GET )

// part number
oLbxB:aCols[3]:nEditType  := If( oRsDetail:fields("LockedDown"):Value = .t., EDIT_NONE, EDIT_GET )
oLbxB:aCols[3]:bOnPostEdit := {|o,v| _InvtLookUp( v, oRsDetail ) }

// type
oLbxB:aCols[4]:nEditType := If( oRsDetail:fields("LockedDown"):Value = .t., EDIT_NONE, EDIT_GET )

// description
oLbxB:aCols[5]:nEditType := If( oRsDetail:fields("LockedDown"):Value = .t., EDIT_GET, EDIT_NONE )
oLbxB:aCols[5]:bEditValue := { || alltrim(oRsDetail:Fields("Item Description"):Value)+space(25) }

oLbxB:aCols[5]:bOnPostEdit := {|o,v| _GetText( v,oLbxB )  }

//  Price
oLbxB:aCols[6]:nEditType := If( oRsDetail:fields("LockedDown"):Value = .t., EDIT_NONE, EDIT_GET )

// ext
oLbxB:aCols[7]:nEditType := EDIT_NONE

// color the columns

 oLbxB:oCol( "Qty" ):bClrStd         := {|| {if(oRsDetail:fields("LockedDown"):Value = .t., CLR_HBLUE, CLR_BLACK), CLR_WHITE  } }
       oLbxB:oCol( "Part Number" ):bClrStd := {|| {if(oRsDetail:fields("LockedDown"):Value = .t., CLR_HBLUE, CLR_BLACK), CLR_WHITE  } }
       oLbxB:oCol( "Type" ):bClrStd        := {|| {if(oRsDetail:fields("LockedDown"):Value = .t., CLR_HBLUE, CLR_BLACK), CLR_WHITE  } }
       oLbxB:oCol( "Ext" ):bClrStd         := {|| {if(oRsDetail:fields("LockedDown"):Value = .t., CLR_HBLUE, CLR_BLACK), CLR_WHITE  } }



// add a new record
oLbxB:bPastEof = {|| _AddNewRow( oRsDetail,nRepairNumber,nAssignedTo,cLoc,oLbxB ) }

...
...


//----------------
Static Func _AddNewRow( oRsDetail,nRN,nTech,cLocation,oBrw )

Local Saying

Saying := "Do you wish to Add a New Record ?"
If MsgYesNo( Saying )
Else
   Return(.f.)
Endif

oRsDetail:AddNew()
oRsDetail:Fields("Repair Number"):Value    := nRn
oRsDetail:Fields("Repair Detail Line"):Value := 0
oRsDetail:Fields("Qty"):Value              := 1
oRsDetail:Fields("Item Description"):Value := space(255)
oRsDetail:Fields("Price"):Value            := 0
oRsDetail:Fields("Tech Number"):Value      := nTech
oRsDetail:Fields("Inventory Id"):Value     := space(50)
oRsDetail:Fields("Inventory Type"):Value   := space(50)
oRsDetail:Fields("Cost"):Value             := 0
oRsDetail:Fields("Covered By Warranty"):Value := .f.
oRsDetail:Fields("Location"):Value         := cLocation
oRsDetail:Fields("Code"):Value             := space(50)
oRsDetail:Fields("Shipping Ref"):Value     := space(64)
oRsDetail:Fields("Serial Number"):Value    := space(50)
oRsDetail:Fields("NoTax"):Value            := 0
oRsDetail:Fields("Warranty Provider"):Value := space(50)
oRsDetail:Fields("Quote Price"):Value      := 0
oRsDetail:Fields("LockedDown"):Value       := .f.
oRsDetail:Update()

oBrw:ReFresh()
oBrw:nColsel(2)
oBrw:SetFocus()

xMode := "A"

Return(.t.)

 


Image
User avatar
Rick Lipkin
 
Posts: 2634
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: xBrowse edit_get cell based on table value at runtime

Postby nageswaragunupudi » Fri Apr 27, 2012 2:19 am

If it is only a matter of deciding between EDIT_NONE, EDIT_GET depending on a condition, then the simpler way is to assign bEditWhen codeblock to the column,

oCol:bEditWhen := { || <ConditionalExpressionReturning .T. or .F.> }
Regards

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

Re: xBrowse edit_get cell based on table value at runtime

Postby Rick Lipkin » Fri Apr 27, 2012 2:28 pm

Rao

Thank you for your suggestion .. I need some additional advice on applying that logic to column 4 which has a 'pull down' array that needs to be defined editable at run-time based on the 'LockedDown' field ..

As can see .. I can activate the column based on the table, but not the additional attributes for EDIT_LISTBOX and the accompanying array of values.

Any suggestions on how I can construct the pulldown array based on my table attribute using this code ?

What you are seeing in the picture is this code .. however the 'LockDown' attribute is set to .t. and you should not be able to edit column 4 .. unfortunately, I have to define the 'EDIT_LISTBOX' and array of values at the creation of the browse and I only want to create them at run-time based on the table attribute.

Rick Lipkin

Code: Select all  Expand view

// type
oLbxB:aCols[4]:bEditWhen := { || If(oRsDetail:fields("LockedDown"):Value = .f., .t.,.f.) }
// drop down for service type
*  oLbxB:aCols[4]:nEditType    := { || If(oRsDetail:fields("LockedDown"):Value = .f., EDIT_LISTBOX,EDIT_NONE )}
oLbxB:aCols[4]:nEditType    := EDIT_LISTBOX
 oLbxB:aCols[4]:aEditListTxt := aType
 


Image
User avatar
Rick Lipkin
 
Posts: 2634
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: xBrowse edit_get cell based on table value at runtime

Postby nageswaragunupudi » Fri Apr 27, 2012 9:58 pm

Code: Select all  Expand view
oLbxB:bChange     := { | oBr | OnRowChange( oBr ) }

//
// other code
//

static function OnRowChange( oBrw )

   WITH OBJECT oBrw:aCols[ 4 ]
      if oBrw:oRs:Fields( "LockedDown" ):Value
         if :nEditType != EDIT_NONE
            :nEditType        := EDIT_NONE
            :aEditListTxt     := ;
            :aEditListBound   := nil
         endif
      else
         if :nEditType != EDIT_LISTBOX
            :nEditType        := EDIT_LISTBOX
            :aEditListTxt     := ;
            :aEditListBound   := aType
         endif
      endif
   END

return nil
 
Regards

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

Re: xBrowse edit_get cell based on table value at runtime

Postby Rick Lipkin » Sat Apr 28, 2012 4:45 pm

Rao

Your solution works GREAT for 'on change' .. and if I move around within the rows. When I create a new row the 'LockedDown' attribute is set to false and the drop down control needs to be activated with the array of values ( since 'LockedDown' is False ) and unfortunately the drop down list control is not active :cry:

I have tried your code on bEditWhen but the results are close but the control is not visible .. For now I have a rather sloppy solution to use the bOnPostEdit code block to keep anyone from editing the field if it is locked .. I would prefer not to see the dropdown on previously locked rows and to be able to click into rows not locked and have the dropdown become visible and activated.

I do not know if this is possible due to the fact you have to define the column and controls with the creation of the xBrowse ??

I know you do not have much time to spend on this trivial matter, but any other suggestions would be welcomed and appreciated.

Rick Lipkin

Code: Select all  Expand view

oLbxB:aCols[4]:nEditType    := EDIT_LISTBOX
oLbxB:aCols[4]:aEditListTxt := aType
oLbxB:aCols[4]:bOnPostEdit  := {|o,v| _GetPullDown( v,oLbxB,oRsDetail ) }

..
..

//-----------------
Static Func _GetPullDown( v,oLbxB,oRsDetail )

// do not allow update if LockedDown is true

If oRsDetail:Fields("LockedDown"):Value = .t.
   Return(.f.)
Else
   oRsDetail:Fields("Inventory Type"):Value := v
   oRsDetail:Update()
Endif

Return(.t.)
 
User avatar
Rick Lipkin
 
Posts: 2634
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 41 guests