Adding buttons to a DataWindow object

Buttons make it easy to provide command button actions in a DataWindow object. No coding is required. The use of Button controls in the DataWindow object, instead of CommandButton controls in a window, ensures that actions appropriate to the DataWindow object are included in the object itself.

The Button control is a command or picture button that can be placed in a DataWindow object. When clicked at runtime, the button activates either a built-in or user-supplied action.

For example, you can place a button in a report and specify that clicking it opens the Filter dialog box, where users can specify a filter to be applied to the currently retrieved data.

StepsTo add a button to a DataWindow object:

  1. Select Insert>Control>Button from the menu bar.

  2. Click where you want the button to display.

    You may find it useful to put a Delete button or an Insert button in the detail band. Clicking a Delete button in the detail band will delete the row next to the button clicked. Clicking an Insert button in the detail band will insert a row following the current row.

    NoteBe careful when putting buttons in the detail band Buttons in the detail band repeat for every row of data, which is not always desirable. Buttons in the detail band are not visible during retrieval, so a Cancel button in the detail band would be unavailable when needed.

  3. With the button still selected, type the text to display on the button.

  4. Display the General page of the Properties view for the button.

  5. Select the action you want to assign to the button from the Action drop-down list.

    For information about actions, see “Actions assignable to buttons in DataWindow objects”.

  6. If you want to add a picture to the button, select the Action Default Picture check box or enter the name of the Picture file to display on the button.

    If you plan to use the DataWindow object as a Web DataWindow, you can use images for default buttons provided in the dwaction.jar file. For more information, see the DataWindow Programmer’s Guide.

  7. If you want to suppress event processing when the button is clicked at runtime, select the Suppress Event check box.

    When this option has been selected for the button and the button is clicked at runtime, only the action assigned to the button and the Clicked event are executed. The ButtonClicking and the ButtonClicked events are not triggered.

  8. Click OK.

What happens if Suppress Event is off

If Suppress Event is off and the button is clicked, the Clicked and ButtonClicking events are fired. Code in the ButtonClicking event (if any) is executed. Note that the Clicked event is executed before the ButtonClicking event.

NoteDo not use a message box in the Clicked event If you call the MessageBox function in the Clicked event, the action assigned to the button is executed, but the ButtonClicking and ButtonClicked events are not executed.

Example

For an example of a DataWindow object that uses buttons, see the d_button_report object in the Code Examples application.

This DataWindow object has several buttons that have default actions, and two that have user-defined actions. In the Properties view in the DataWindow painter, these buttons are named cb_help and cb_exit. Suppress Event is off for all buttons.

In the Window painter, the Clicked and ButtonClicking events for the DataWindow control that contains d_button_report are not scripted. This is the ButtonClicked event script:

string	ls_Object
string	ls_win

ls_Object = String(dwo.name)

If ls_Object = "cb_exit" Then
	Close(Parent)
ElseIf ls_Object = "cb_help" Then
	ls_win = parent.ClassName()
	f_open_help(ls_win)
End If

This script is triggered when any button in the DataWindow object is clicked.