OpenDialog Filter problem. Not working.

I cannot seem to get the file type filter option to work for openfiledialog. When I use d.Filter=".txt" it compiles and runs but does not filter anything. I only want to see text file (txt) extension files in a folder.
From an example I tried dim f as folderitem = GetOpenFolderItem(filetypes1.text), and I got an error saying it does not know filetypes1.

When the code does run the dialog box does not show the second line with the file type names in it to select from. Can anyone help me? I am just too new to xojo to know where else to look.

You would need the extension in your code and not filetypes1.text.

You need to dim the FileType:

dim theDialog as new SaveAsDialog theDialog.Title = kSaveArchive theDialog.SuggestedFileName = kArchive + "." + FileTypes.DB.Extensions Dim DBType As New FileType dbType.Name = "vdb" dbType.Extensions = "vdb" theDialog.Filter = DBType dim theResult as FolderItem= theDialog.ShowModal

I think the bug can go to school now as it’s rather old.

[code]Dim txtType As New FileType
txtType.Name = “Text File (*.txt)”
txtType.Extensions = “txt”

d.Filter=txtType[/code]

Beatrix was a second faster.

Dialog filters on the Mac haven’t worked for years. The docs say .Filter accepts a string, not a FileType, but that only works on Windows.

There is a Feedback report for this, #45392.

I’m really glad to see this new method works! It can also be used with existing FileTypes:

'MyFileTypes.TextFile is an already-defined FileType in the project

dim FType as new FileType
FType.Name = "Text File"
FType.Extensions = MyFileTypes.TextFile.Extensions

theDialog.Filter= FType

BTW, this FileType method works as far back as Xojo 2016R3, maybe even older.

I updated the Feedback report to show this as a workaround and to request updating the documentation to show that dialog.filter accepts FileType.

Thank you, Beatrix and Axel, for showing us how to make this work!

Note that using a FileType as a filter in this way doesn’t work with the SaveAsDialog.

For that, you’ll still need to do this:

theSaveAsDialog.Filter=MyFileTypes.TextFile

(without .Extensions)

So, you go to the LR and learned that a FileType is an object you can Add to the Project using the Insert MenuItem…

Edit: typos.

Thanks to you all! I am so new I’m embarrassed to ask, but I simply couldn’t find a working example!

Look there (as an example):

http://documentation.xojo.com/index.php/FileType

Don’t be embarrassed, we’ve all run into something puzzling at one time or another - and why we’re thankful for all of the helpful folks on this forum!

Well, newbieitis was my problem. I eventually found a reference to file types and worked it out. I did notice a STRANGE thing. When I try to drag the FileType control to the window, it won’t take, but if I drag it to the navigator it sticks. I haven’t this documented anywhere and is very confusing to me.