ListBox.EnableDrag
Warning
This item was deprecated in version 2019r2. Please use DesktopListBox.AllowRowDragging as a replacement.
Description
Allows rows to be dragged.
Sample code
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:
Function DragRow(drag As DragItem, row As Integer) As Boolean
drag.Text = Me.List(row)
Return True ' allow the drag
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
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:
Function DragRow (drag As DragItem, row As Integer) As Boolean
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.
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
Compatibility
All projects types on all supported operating systems.