Drag row from Listbox to drop in Textfield

I’m working through this and curious if anyone has code on this.
Thanks

Well, it depends.
If your TextField is in another, non Xojo, application, you can simply drag text to it.
If your TextField is in the same application, the TextField apparently won’t accept plain text (as my testing did prove, even if I find it weird).

So, first the obvious, turn on “Allow Row Dragging” to the listbox. Then, implement its DragRow event, like this:

Function DragRow(drag As DragItem, row As Integer) Handles DragRow as Boolean
  drag.Text=me.Cell(row,0) 'e.g. for cocoa apps (TextEdit, etc.)
  drag.PrivateRawData("mtxt")=me.Cell(row,0) 'For your own application
  Return True
End Function

Your TextField’s Open event would look like this:

Sub Open() Handles Open
  me.AcceptRawDataDrop("mtxt")
End Sub

And the TextField’s DropObject may look like that:

Sub DropObject(obj As DragItem, action As Integer) Handles DropObject
  dim s As String=obj.RawData("mtxt") 'The data added in the listbox's DragRow event
  
  if s<>"" then me.SelectedText=s 'Alternatively, check for IsRawDataAvailable("mtxt")
End Sub

Thank you.
I’m working through this and know enough to be dangerous.
I get error messages with the Sub’s and Functions and End Subs and End Functions.
I put them in the proper event, but just get errors. What am I doing wrong?

I used ContainerControl to make drag and drop work.

Here’s my tutorial: https://theretaildetail.us/2020/10/11/xojo-2019r3-2-drag-and-drop-custom-control-set/

Hope this helps!

So, your “ListBox” is actually a ContainerControl that embeds “row” type smaller ContainerControl and when you drag, the text is saved to a Var and then the TextField is then populated with that Var. After that code runs, whatever you want to do with your row container (some apps would be designed for them to disappear from the set of available “row” containers)… See the tutorial for more in-depth information.

See example “DownloadContainer” in the Xojo examples folder. NSTableViewMBS also has an example for a scrollable listbox with containers.