How can I show only certain file extensions in an open file dialog?

When I open a folder with OpenDialog, how can I filter it so that users can see only certain files (for example, Stringgrid, * .sg), and files with any other extension do not appear in the dialog box?

+6
source share
2 answers

Set the OpenDialog.Filter property to the filter for the filter. You can do this in the Object Inspector; click in the Filter property and you will see a small button on the right edge with ... Click this and you will see a dialog box. The left side is the file description (for example, Excel files (*.xls) ). The right side is the filter you want to use, as in *.xls .

OpenDialog Filter Dialog

You can also set it in code before displaying a dialog:

 OpenDialog1.Filter := `Excel files (*.xls)|*.xls`; 

Of course, replace the Excel material with any description and mask that you want to use.

+9
source

The Filter and FilterIndex properties are used to specify the file extension (s) (note that the user can manually override the filter).

The OnIncludeItem event OnIncludeItem used to selectively enable / disable individual files / folders from the list in the dialog box.

+2
source

Source: https://habr.com/ru/post/902508/


All Articles