When I open a folder with an OpenDialog, how can I filter it so users can view only certain files (e.g., Stringgrid, *.sg) and the files with any other extension do not appear in the dialog window?
Asked
Active
Viewed 1.5k times
8
-
2No, you can't do the second (filter files based on something other than extension) if they're in the same folder. But the right solution for that is to give each user their own folder to store files, and use access control (folder rights) to prevent users from seeing each other's files. – Ken White Nov 28 '11 at 00:38
-
1I've removed your second question because it's too different from the original one. Please ask your other question in a separate post. – Rob Kennedy Nov 28 '11 at 16:55
2 Answers
13
Set the OpenDialog.Filter
property to the file filter you want.
You can do this in the Object Inspector:
- Click in the
Filter
property, and you'll see a small button appear on the right edge with...
. - Click that, and you'll see a dialog appear.
On the left side is the description of the file (for instance, Excel files (*.xls)
). The right side is the filter you want to use, as in *.xls
.
You can also set it in code before displaying your dialog:
OpenDialog1.Filter := 'Excel files (*.xls)|*.xls';
Of course, replace the Excel stuff with any description and mask you want to use.

LuizLoyola
- 386
- 3
- 20

Ken White
- 123,280
- 14
- 225
- 444
2
The Filter
and FilterIndex
properties are used to specify which file extension(s) to display (note that the user can override the filter manually, though).
The OnIncludeItem
event is used to selectively allow/disallow individual files/folders from being listed in the dialog.

Remy Lebeau
- 555,201
- 31
- 458
- 770