Drop Rows from ListBox into a Desktop folder

I want to export the selected Row(s) into a desktop (file or TextClipping). I will later read them back.

I know how to collate Rows into a string (for example), but I do not discover how to drag the result into a file in the desktop.

Ideas ?

TIA

See on Xojo documentation:

Dim t As TextOutputStream
Dim f As FolderItem
f = specialFolder.Desktop.child(“CreateExample.txt”)
If f <> Nil Then
t = TextOutputStream.Create(f)
t.WriteLine(MyListbox.cell(0,0))
t.Close
End If

@Horst: Do you work for Microsoft by any chance? :wink:

Hi Horst,

Thanks, and yes, you are right. This is a way I can use in a ContextualMenu or/and in a MenuBar MenuItem. (Good idea)

What I had in mind (and I forgot to wrote (because my prior attempt was lost in the cyberspace…) was to drag the selected rows to desktop (and drag that file from the desktop into the ListBox, later).

The ListBox drag example si tod rag rows from a ListBox to another.

I’ve “scanned” the Xojo documentation, but found nothing. There can be something I do not saw (it happens to me sometimes).

for TextClipping (OSX) all you need is
enable Drag for your Listbox

and in ListBox.DragRow

drag.Text = me.Cell(row, -1)

and drop the TextClipping back

ListBox.Open
me.AcceptTextDrop

ListBox.DropObject

  Dim xValue As Integer
  xValue = System.MouseX - Me.Left - Self.Left 
  Dim yValue As Integer
  yValue = System.MouseY - Me.Top - Self.Top 
  
  Dim row, column As Integer
  row = Me.RowFromXY(xValue, yValue)
  column=Me.ColumnFromXY(xValue, yValue)
  
  if obj.TextAvailable then
    me.cell(row, -1) = obj.Text
  end if

Thank you Axel.

Besides adding (before any Row):
drag.Text = “TextClipping File Name” + EndOfLine

Is it possible to set by code a file name to the TextClipping file ?

I think if you want a filename you must use txt
(here i use column 1 as filename)

    dim f as FolderItem = SpecialFolder.Temporary.Child(me.Cell(row, 1)+ ".txt")
  if f <> nil then
    dim tis as TextOutputStream
    tis = TextOutputStream.Create(f)
    tis.Write me.Cell(row, -1)
    tis.close
    drag.FolderItem = f
  end if

and add in DropObject

  if obj.FolderItemAvailable then
    dim tis as TextInputStream = TextInputStream.Open(obj.FolderItem)
    me.Cell(row,-1) = tis.ReadAll
    tis.Close
  end if

and in Open
me.AcceptFileDrop("")

Thank you Axel.

But what is the purpose of Drag.FolderItem and Drag.FolderItemAvailable ?

beside:

If Drag.FolderItemAvailable Then // Use Drag.FolderItem here [but how ?] End If

That answer (above) was sent too fast.

I have to study your example (compare with what I already have, but a first look let me think I wrote similar code, in DragRow *).

The last idea that comes to my mind is to use the FolderItem.Parent of the current data as the target folder (like Initial Folder) and save the Row(s) there with a specific name (Exported R)ws " + Date.Something…

I do not had time yet to experiment that.

  • At first, I think that the code does not works due to an example I probably misread / misunderstand, but after a reboot (yesterday evening ?) I noticed a Temporary folder n my trash and found all my “drag” created with TextOutputStream… there !

Search the docs and forums for “promised file”. When you drag from an app to the filesystem, it is called a promised file and is different from a normal drag/drop. It is supported on Mac, but not Windows or Linux, if my memory serves.

Hi Tim,

thank you for your kind answer. Your memory is correct.

I saw the “promised file” words earlier, but probably because it is not XPlatform, I skipped it.

It is in the DragItem entry.

I think that I will keep the idea I expressed earlier (use the reference to the currently opened file and store my clipping / TOS ? there).
Thanks all for the brain storming.