Occurs when the current row is about to change in the DataWindow. (The current row of the DataWindow is not necessarily the same as the current row in the database.)

The RowFocusChanging event occurs just before the RowFocusChanged event.

PowerBuilder event information

Event ID: pbm_dwnrowchanging




Long by value. The number of the row that is current (before the row is deleted or its number changes). If the DataWindow object is empty, currentrow is 0 to indicate there is no current row.


Long by value. The number of the row that is about to become current. If the new row is going to be an inserted row, newrow is 0 to indicate that it does not yet exist.

Return Values

Set the return code to affect the outcome of the event:

0 -- Continue processing (setting the current row)

1 -- Prevent the current row from changing

For information on setting the return code in a particular environment, see About return values for DataWindow events.


Typically the RowFocusChanging event is coded to respond to a mouse click or keyboard action that would change the current row in the DataWindow object. The following methods can also trigger the RowFocusChanging event, as well as the RowFocusChanged and ItemFocusChanged events, when the action changes the current row:


In these cases, the RowFocusChanging event script can prevent the changing of the DataWindow object's current row only. The script cannot prevent the data from being changed (for example, the rows still get moved).

When you use the ScrollToRow method to change focus, the RowFocusChanging event is triggered before the scroll occurs, and the RowFocusChanged event is triggered after the scroll occurs.

In a tabular DataWindow, if the user clicks to change rows, the row focus does not change, and the row and DataWindow do not scroll. You can still scroll programmatically or by using the scroll bar.

In a read-only DataWindow, when you click on any column that is not in the current row, the RowFocusChanging and RowFocusChanged events fire, but the current column is not changed -- the current column remains at 0, since no column can have focus. DataWindows are read-only if updates are not allowed, all tab orders are set to 0, or all tab columns are protected.

However, if focus is on an editable column in an updatable DataWindow (a DataWindow that has one or more editable columns), the row focus events do not fire when you click on a protected column or on a column whose tab order is 0. The focus remains on the current, editable column.

If focus moves off an editable column in an updatable DataWindow, the DataWindow switches to read-only mode. This can happen when the last row in the DataWindow does not have an editable column. In this case, tabbing off the last editable column causes the row focus to move to the row following the row with the last editable column. The DataWindow then remains in read-only mode until focus is given to an editable column.


This example displays a message alerting you that changes have been made in the window dw_detail which will be lost if the row focus is changed to the window dw_master.

IF dw_detail.DeletedCount() > 0 OR & 
         dw_detail.ModifiedCount() > 0 THEN
      MessageBox("dw_master", "Changes will be lost &
         in Detail")
      RETURN 0

See also