buttonpowerbuilderdatawindow

How to handle buttonclicked event of DDDW?


Situation: I have a button in my DDDW and i want to capture buttonclicked event.

Problem: when i click on the button in DDDW the buttonclicked event of DW Control is not fired and ItemChanged event is fired for DW control.

Question: How do i capture buttonclicked event for the button in DDDW? Or is there any other way i can delete a row from DDDW when delete button is clicked for a particular row?

enter image description here

PowerBuilder 12.5


Solution

  • According to the PB help, a DataWindowChild has no events :|

    But, that doesn't mean we still can't hook into it via the DW control's itemchanged event. Note: this is a hack, and underwent some very-limited testing. But, it demonstrates a point, I guess.

    Here's what I did:

        // dw_1::itemchanged
        //
        //  - DDDW is named "profession"
        IF dwo.Name = "profession" THEN
            IF IsValid(idwc_profession) THEN
                string ls_clickedobject
                // Get the DataWindowCHILD object where the pointer was clicked:
                ls_clickedobject = idwc_profession.GetObjectAtPointer()
    
                IF IsNull(ls_clickedObject) OR (ls_clickedobject = "") THEN RETURN
    
                // Return from GetChild is <column name>~t<row number>; let's get
                // the position of the tab character so we can parse it
                long ll_tabPos
                ll_tabPos = Pos(ls_clickedObject, "~t")
    
                IF ll_tabPos > 0 THEN
                    string ls_clickedDddwColumn
    
                    ls_clickedDddwColumn = Trim(Left(ls_clickedObject, ll_tabPos - 1))
                    // Check to see if we've clicked on the computed field with the delete button
                    IF Lower(ls_clickedDddwColumn) = "delete_button" THEN
                        long ll_clickedDddwRow
                        // grab the row we want to delete
                        ll_clickedDddwRow = Long(Trim(Right(ls_clickedObject, Len(ls_clickedObject) - ll_tabPos)))
    
                        IF ll_clickedDddwRow > 0 THEN
                            // delete the row from the DDDW
                            idwc_profession.DeleteRow(ll_clickedDddwRow)
    
                            SetNull(data) // reset our data
                        END IF
                    END IF
                END IF
            END IF
        END IF
    
    RETURN
    

    Also note that you may have to play around with the return value from itemchanged to get it to do what you want. And, if you want to automatically dropdown the DDDW again after the deletion happens, you'd might be able to use the Send() method to do so (I don't know the right "number" for that, though).