ListBox.DragReorderRows

From Xojo Documentation

Event


ListBox.DragReorderRows(newPosition As Integer, parentRow As Integer) As Boolean

Supported for all project types and targets.

This event is called when one or more rows are selected then moved in the ListBox to a new position. The ListBox.EnableDragReorder property must be True in order for this event to be called.

Notes

For Non-Hierarchical ListBoxes

  • The newPosition parameter is the (0-based) row number at which the dragged row was dropped. Remember that the first row in a ListBox is numbered zero. This row number is adjusted assuming that all selected rows will be moved as implied by the drag & drop action.
  • The parentRow parameter will always be -1, because it has no significance for a non-hierarchical ListBox.

The row(s) to be reordered are selected before this event fires. If the SelectionType is set to single, you can use SelectedRowIndex to get the number of the only selected row. If the SelectionType is set to multiple, you must go through all rows in the list and check if Selected is True for each row (see example in Selected).

For a non-hierarchical ListBox, row reordering is done for you if you return False. To override the automatic behavior so you can do the row reordering yourself (for customization purposes), return True.

For Hierarchical ListBoxes

  • The newPosition parameter is the row number at which the dragged row was dropped. Remember that the first row in ListBoxes is numbered zero.
  • If the newPosition is inside a folder (see AddFolder and InsertFolder) the parentRow parameter is the row number that folder, i.e. the parent of the newPosition. Otherwise, parentRow will be -1. This happens if the newPosition is before the first folder in the list, i.e. the root level of the ListBox.
  • For both parameters, the row numbers are adjusted assuming that all selected rows will be moved as implied by the drag & drop action.

The row(s) to be reordered are selected before this event fires. If the SelectionType is set to single, you can use SelectedRowIndex to get the number of the only one selected row. If the SelectionType is set to multiple, you must go through all rows in the list and check if Selected is True for each row (see example in Selected).

For a Hierarchical ListBox, row reordering is NOT done for you, regardless of the value you return. You are responsible for writing the code for reordering the rows and you should return True.