Drop a FileItem on a Listbox

Once more.

I notices (because of an error from me) that my Listbox get pdf files (and generate tons of troubles, of course). Once the feature I debugged was done, I checked that.

In Window1.Open, I do not have AcceptFileDrop…

In (Listbox) LB.Open, I have three AcceptFileDrop. I commented two of them (Raw TXT and CSV) and keep SQLite (naked: only file extension is filled).

I checked the Editors and disable .TXT and .CSV to be sure they will not interfere with the Window1.Open code.

Run in the IDE and I was able to drop a Raw Text File and get its contents (by chance, that text holds valid data (but it was a service file sued elsewhere in the application). More surprising, a DOC file (Word ?) is accepted(I get the tons of troubles I talked above.

Must I add a second filtering schema in LB.DropObject like:

If DropFI.Directory Then Return // Reject directories drops If Right(DropFI.Name,3) = "PDF" Then Return // Reject PDF drops If Right(DropFI.Name,3) = "DOC" Then Return // Reject DOC drops

to exclude some entries.

Must I use some way to accept the file extensions I want to accept ?
(Like If Right(DropFI.Name,6) = "SQLite" Then… but in this case, I have to wrote as many lines as I have file extensions.

And I do not talk about the other file types I will accept later (like XML, JSON, etc.).

For the sake of the test, I commented all Me.AcceptFileDrop lines from LB.Open: I do not found any Item that is accepted (so a part of the mechanism works).

That Window1 only deals with text data that are displayed with a Listbox (LB).

BTW: my project is build (developped) using Xojo 2015r1. However, before writing a report here, I load my project with the latest Xojo release (in this case: 2016r3), just in case I found a squashed bug (a bug that was removed between the two release).

I will share a beta of this application later, once this trouble will disappear. It is not fully featured (some are incomplete), but I hope it is bug free (as free as possible: I do not know any)*

  • until some appears for unknow reason. For example: print in colours works now file excepted that the (first in the test) is incomplete: the last 10 lines are printed in the next page (Landscape). I am acustomed to these mysteries.

Try this FileTypes fix.

Thanks Tim, but the question is for drag and drop, that forum entry is for Open and unless its too late in the evening for me to use Xojo, the forum entry talks about Open only.

[quote=296300:@Tim Parnell]Try this FileTypes fix.


Emile, your post read like the Drag/Drop FileTypes filter wasn’t working.
FileTypes editor in the IDE is broken, the workaround is to define FileTypes in code.

Did you try the workaround or did you just shut the idea down without consideration?

This is what I’ve done (with my FileType1, of course).

Yes, it is broken.
My eyes started to close by themselves, so I shutdown and go to sleep.

Now it is the morning and I do not fired Xojo yet.

I awaken with the idea to use a Select Case to deal with my accepted file types as a filter. I will modify my current code who already makes some filtering (but obviously not as rigid as needed) and to put the Method calling code in a Select Case block.

The idea is to take the file extension using CountFields / NthField using the last dot as field separator (my file extensions does not holds any dot in them, so they are the last field), then in Case use text, csv, etc. as filter and call the appropriate method loading for the extension.
The Else wil simply hold a Return statement.

And since Case Var1, Var2, Var3 works, this my do the trick.

I do not had time yet to wrote it and check how it works.

What put my brain in infinite loop yesterday was the length of an If / End If block with so many (7?) file extension checks in the If line. As you can read far above, code to reject a directory (or a specific file extension) works fine. But I prefer filter what I want (less to filter) than what I do not want (far more).

Now, I can [quote=296340:@Tim Parnell]define FileTypes in code[/quote].

Thank you Dave and Tim for your advices / clues. I will report my conclusions.

PS: I really was tired, I forgot to add that I was running in OS X (for the testings), but X-Platform on the end.

The following code allows text file drops in the Listbox (the code is located in LB.Open):

[code] Dim FT_SQLite As New FileType

FT_SQLite.Name = “SQLite Document”
FT_SQLite.Extensions = “SQLite”
Me.AcceptFileDrop FT_SQLite[/code]

This is the test using Select Case Item_Ext:

[code] Dim Item_Ext As String
Dim Item_Cnt As Integer

// How many “fields” ?
Item_Cnt = CountFields(DropFI.Name,".")

// Get the file Extension
Item_Ext = NthField(DropFI.Name,".",Item_Cnt)

// Deals with the accepted files (and reject the unwanted)
Select Case Item_Ext
Case "txt"
  // Deals with RAW TEXT files
Case "csv"
  // Deals with CSV files
Case "json"
  // Deals with JASON files
Case "sqlite", "cdb", "rdb"
  // Deals with SQLite files
Case "xml"
  // Deals with WML files
  MsgBox "Else du Select Case Item_Ext" + EndOfLine + EndOfLine +_
  "File Extension of the dropped file: " + Item_Ext

  // Unwanted file extension: reject it !
End Select[/code]

DropFI is a reference to the dropped FolderItem.

I do not placed call to load the different accepted files, but for the test, I put in Else a MessageBox to report rejected items. (of course, it will be removed asap).

This seems to works fine.

Warning: If you want to acccept file extensions that are in two parts using a dot as file extension separator, the code above will break. This is not my case.

Back home. I copy the code to deal with each of the Case, then commented the old (and long) If / End If previous block.

I ran the project, drop a bunch of files (and folders / .app, etc.): the dropped items are handled the way I intended to.

Thank you all.