You can use the MOVE-COLUMN() method to rearrange the columns within a browse. For example, rather than forcing the users to scroll horizontally to see additional columns, you might allow them to reorder the columns. MOVE-COLUMN takes two arguments:

  • The integer sequence within the browse of the column to move, counting from left to right
  • The integer position to move the column to, again counting from left to right

The following simple example shows how to use the MOVE-COLUMN method along with the START-SEARCH event and the column attributes introduced earlier.

The START-SEARCH event occurs when the user clicks on the column header for a browse with enabled columns. You can use this event to sort by column or for other purposes. In this case, you want to identify which column position was selected and move this column one position to the left.

To rearrange the columns you see first in the viewport without scrolling

Define this START-SEARCH trigger block for the OrderBrowse:

DO:
  DEFINE VARIABLE hColumn AS HANDLE NO-UNDO.
  DEFINE VARIABLE iColumn AS INTEGER NO-UNDO.
  hColumn = SELF:FIRST-COLUMN.
  DO iColumn = 1 TO SELF:NUM-COLUMNS:
    IF hColumn = SELF:CURRENT-COLUMN THEN LEAVE.
    hColumn = hColumn:NEXT-COLUMN.
  END.
  IF iColumn NE 1 THEN
  SELF:MOVE-COLUMN(iColumn, iColumn - 1).
END.

Whenever you enter a trigger block, the SELF keyword evaluates to the handle of the object that initiated the event. In this case, this is the browse itself, not the browse column. The CURRENT-COLUMN attribute returns the handle of the column the user clicked on.

The code initializes the hColumn handle variable to the first column in the browse and then walks through all the columns, looking for the one with the same handle as the browse’s CURRENT-COLUMN. This identifies the sequential position of the one selected. The MOVE-COLUMN method moves this column one position to the left, unless the user selected the first column.

You can also let the user simply drag columns left or right by setting the browse COLUMN-MOVABLE attribute to true or an individual column’s MOVABLE attribute to true, as described in Move the browse.