ListBox.EnableDrag
From Xojo Documentation
This item was deprecated in version 2019r2. Please use ListBox.AllowRowDragging as a replacement. |
or
BooleanValue = aListBox.EnableDrag
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 EnableDrag property set to True and its SelectionType property set to zero (Single). Its DragRow event handler is as follows:
drag.Text = Me.List(row)
Return True // allow the drag
ListBox2's Open event handler has the line:
Its DropObject event handler is this:
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 EnableDrag property set to True, enabling items in its list to be dragged, and its SelectionType property set to 1 (Multiple row selection). Its DragRow event handler is as follows:
Dim nRows, i As Integer
nRows = Me.ListCount - 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.
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.
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.