DesktopListBox.AllowRowDragging

From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Property (As Boolean )
aDesktopListBox.AllowRowDragging = newBooleanValue
or
BooleanValue = aDesktopListBox.AllowRowDragging

New in 2021r3

Supported for all project types and targets.

Allows rows to be dragged.

Examples

Drag and Drop between ListBoxes

The following example allows the user to drag one row from ListBox1 to ListBox2. ListBox1 has its AllowRowDragging property set to True and its RowSelectionType property set to zero (Single). Its DragRow event handler is as follows:

Function DragRow(drag As DragItem, row As Integer) As Boolean
drag.Text = Me.List(row)
Return True // allow the drag
End Function

ListBox2's Open event handler has the line:

Me.AcceptTextDrop

Its DropObject event handler is this:

Sub DropObject(obj As DragItem)
Me.AddRow(obj.Text) // adds the dropped text as a new row
End Sub

Drag and Drop Multiple Rows between ListBoxes

The following example allows the user to drag more than one row from ListBox1 to ListBox2. The dragged rows are added to the end of the list.

ListBox1 has its AllowRowDragging property set to True, enabling items in its list to be dragged, and its RowSelectionType property set to 1 (Multiple row selection). Its DragRow event handler is as follows:

Function DragRow (drag As DragItem, row As Integer) As Boolean
Var nRows, i As Integer
nRows = Me.RowCount - 1
For i = 0 To nRows
If Me.Selected(i) Then
drag.AddItem(0, 0, 20, 4)
drag.Text = Me.List(i) // get text
End If
Next
Return True // allow the drag
End Function

It uses the AddItem method of the DragItem to add an additional item to the DragItem each selected row. The DropObject event handler then cycles through all items to retrieve all dragged rows.

ListBox2 has the following line of code in its Open event handler. It permits it to receive dragged text.

Me.AcceptTextDrop

Its DropObject event handler checks to see if the dragged object is text; if it is, it adds a row to the end of the list and assigns the text property of the dragged object to the new row: It loops through all items in the DragItem until NextItem returns False.

Sub DropObject(obj As DragItem)
Do
If obj.TextAvailable Then
Me.AddRow(obj.Text)
End If
Loop Until Not obj.NextItem
End Sub

You can also drag from ListBox1 to the desktop to get a text clipping or to another application that supports text drag and drop.