The CommonDialog's Filter property is a string with the format:
text1|value1|text2|value2...
The text parts are displayed to the user. The values are used as the file filters. Consider this example (all one line):
Text Files (*.txt)|*.txt|Graphic Files (*.bmp;*.gif;*.jpg)|*.bmp;*.gif;*.jpg|All Files (*.*)|*.*
This makes the control use these values:
Text Value | File Filter |
Text Files (*.txt) | *.txt |
Graphic Files (*.bmp;*.gif;*.jpg) | *.bmp;*.gif;*.jpg |
All Files (*.*) | *.* |
This is a bit confusing.
This example uses the AddFilter routine to make adding new filters to the property easy.
|
' Add a filter to the dialog in an easy way.
Private Sub AddFilter(ByVal dlg As CommonDialog, ByVal _
filter_title As String, ByVal filter_value As String)
Dim txt As String
txt = dlg.Filter
If Len(txt) > 0 Then txt = txt & "|"
txt = txt & filter_title & " (" & filter_value & ")|" & _
filter_value
dlg.Filter = txt
End Sub
Private Sub Form_Load()
' Load filters.
CommonDialog1.Filter = ""
AddFilter CommonDialog1, "Text Files", "*.txt"
AddFilter CommonDialog1, "Graphic Files", _
"*.bmp;*.gif;*.jpg"
AddFilter CommonDialog1, "All Files", "*.*"
End Sub
|