This tip was submitted by Rene Bajarias
and provides a solution for people using PowerBuilder 5 to have buttons on
a variety of datawindow styles including tabular.
Still using PB 5.x and wishing it had the ability to drop command buttons on a datawindow? Well, with a little bit of tweaking, you can simulate command buttons in a datawindow - be it a freeform or a tabular type of dataobject. Here's how:
1) Create a new application called dwbutton.pbl
2) Create an application object called dwbutton. Click on "No" to prevent PowerBuilder from generating an application template.
3) Create a new datawindow object with "External" (although it can also have Tables as its data source) as its Data Source and "Tabular" (it can also be "Freeform" or whatever) as its Presentation Style. Click OK. In the Result Set Description window, type the following column name and its data type:
Click OK. Within this dataobject, create a text object in the Detail band with a text of "Click Me!". Name this text object "button1_t". Change the Border property of this text object to "3D Raised". Set the background color to "ButtonFace". Click OK. Set the Tab Order of the "flag" column to 0. Set the color of the dataobject to "ButtonFace" also. Save this dataobject as "d_dwbutton".
4) Create a new window and drop a datawindow control object on it. Assign the dataobject that we just made (d_dwbutton) as its DataWindow Object Name. Resize the datawindow control so that it nicely reveals the underlying dataobject. Declare a user event for this datawindow control called "ue_lbuttonup" with "pbm_dwnlbuttonup" as the Event ID. Click OK. In the "clicked" event of this datawindow control, type:
IF dwo.Name = 'button1_t' THEN
Object.flag[row] = 1
ls_x = Modify("button1_t.Border='0~tIf(flag=1, 5, 6)'")
IF Trim(ls_x) <> '' THEN MessageBox('Error', ls_x)
Then in the "ue_lbuttonup" event of this same datawindow control, type:
Object.flag[GetRow()] = 0
Object.button1_t.Border = '6'
IF Pos(GetObjectAtPointer(), 'button1_t' ) > 0 THEN
// Place whatever code you might want to do here.
In the "Open" event of the new window, type:
FOR li_i = 1 TO 5
Save this new window as "w_dwbutton".
5) In the "Open" event of the application, type:
6) Finally, run the application.
Using basically the same technique, you can also have picture buttons in a
dataobject. Click here to
Download the code.