0

i'm new to PowerBuilder 10.5 i'm trying to create a cost application , i want to autocomplete the row when i pick a enter image description herematerial from a DDDW i want to auto fill the price & unit. there are 2 tables 1Material - Unit - Price 2- Itemname DDDW - Quantity - Unit - Price i did it on MSaccess but i don't know how to code it on PowerBuilder on access the code was

Private Sub ItemName_AfterUpdate()
Unit = ItemName. Column(2)
Price = ItemName. Column(3)
End Sub

how can i do it in PowerBuilder

chicco
  • 1
  • 2

2 Answers2

1

Code the following in the ÌtemChanged event of your detail datawindow (of course the code must be adapted to your specific situation):

decimal ld_qty, ld_unitprice

if Upper(dwo.name) <> 'ITEM' then
     return
end if
select qty, unit_price into :ld_qty, :ld_unitprice from your_table where your_table.key = data;

dw2.SetItem(row, 'your_dw_col_qty', ld_qty)
dw2.SetItem(row, 'your_dw_unit_price', ld_unitprice)
1

If you have included the quantity and price with the data retrieved as part of the datawindow object you are using for the DDDW you can access it without another database call. Something like this (in itemchanged event):

datawindowchild dwc
string ls_name
long ll_row

IF Upper(dwo.Name) = "ITEM" THEN
    GetChild("item", dwc)
    ls_name = data
    dwc.SetFilter("name = '" + ls_name +"'" )
    dwc.Filter( ) // filter to specific row in dddw
    ll_row = dwc.RowCount( ) // How many? Use the last one.
    if ll_row > 0 then
        SetItem(row, "cost", GetItemDecimal('cost', ll_row))
        SetItem(row, "amount", GetItemDecimal('amount', ll_row))
    end if
end if
Eric Glenn
  • 389
  • 2
  • 12
Matt Balent
  • 2,337
  • 2
  • 20
  • 23
  • I would prefer `Upper(dwo_name) = 'ITEM'`. Otherwise, it will never happen. +1 for this test anyway. I change my answer accordingly. – Marc Vanhoomissen Oct 24 '17 at 07:47
  • Filter() returns 1 or -1 Should it be something more like? dwc.Filter( ) // filter to specific row in dddw ll_row = dwc.RowCount( ) // How many? Use the last one. if ll_row > 0 then SetItem(row, "cost", GetItemDecimal('cost', ll_row)) SetItem(row, "amount", GetItemDecimal('amount', ll_row)) end if – Eric Glenn Oct 26 '17 at 22:33
  • @EricGlenn correct - I was confusing the Find method which would work as well. – Matt Balent Oct 26 '17 at 22:41