1

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

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136
Shoki
  • 21
  • 12

1 Answers1

1

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:

  • Created a DataWindow with the code and name columns, and a computed field (for the red X) named delete_button
  • Created another DataWindow and painted that DW as a DDDW on there, named profession
  • In my window control's open event, I got the DDDW from the DW and stuck it in an instance variable: dw_1.GetChild("profession", REF idwc_profession)
  • Then, coded the itemchanged event for the DW control:
    // 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).

Frank Alvaro
  • 468
  • 4
  • 12
  • 1
    Creative. As far as that windows message to drop a combo box down, I think it's Const CB_SHOWDROPDOWN = &H14F – Rich Bianco May 25 '19 at 07:00
  • Nice idea. anyway, if profession name is misspelled then new code is already given and two codes exist for the same profession. Selection from DDDW is the time when most user finds that mistake. so there is delete button. Actually, delete button in DDDW makes no sense to me more than that. for example a tray full of different candies is presented to me and i keep throwing those i dont like and then pick the one i like is sure kind of stupid thing Sybase did not do. I cannot think of any other situation where delete button is important in DDDW. – Shoki May 28 '19 at 09:24
  • Itemchanged cannot fire where data value is same as column value. – Shoki May 28 '19 at 09:29