Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleEasily add filters to a CommonDialog control
KeywordsCommonDialog, filters
CategoriesControls
 
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 ValueFile 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
 
Formatted by Neil Crosby
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated