Make your own free website on

Datawindow Buttons in PB5 (Rene Bajarias)

Back Up Next

Author: Rene Bajarias (08 jul 2000)
Download: Download (6Kb) (,6Kb)

Creating Command Buttons on a DataWindow

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:

Create a new application called dwbutton.pbl

Create an application object called dwbutton. Click on "No" to prevent PowerBuilder from generating an application template.

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:

flag number

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".

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:
string ls_x
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:
int li_i
FOR li_i = 1 TO 5

Save this new window as "w_dwbutton".

In the "Open" event of the application, type:


Finally, run the application.

Using basically the same technique, you can also have picture buttons in a datawindow object.

Rene can be reached at


Back Up Next