Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

multiple file type filter on same line of common dialog

1,108 views
Skip to first unread message

Will

unread,
Oct 22, 2004, 2:47:46 PM10/22/04
to
I am working on an application (VB6) in which the user can open a common
dialog box to choose an image file. I want the filter to display jpg, gif
and bmp files (only) all in the same browse box.
How can I do this so they all appear on the same line of the drop down
rather than seperate lines for each file type?


Stoil Marinov

unread,
Oct 22, 2004, 3:19:08 PM10/22/04
to

"Will" <Wi...@bigpond.com> wrote in message
news:mBced.35665$5O5....@news-server.bigpond.net.au...


Hi Will,

Set the Filter property to the following string:
"Image files (*.jpg, *.gif, *.bmp)|*.jpg, *.gif, *.bmp|All files (*.*)|*.*"

This will create two choices in the dialog: "Image files" and "All files"

Regards,

Stoil Marinov


Will

unread,
Oct 23, 2004, 2:16:25 AM10/23/04
to
Thanks I nearly got it right, had the commas but not the space after.Your
help is gratefully appreaciated.


"Stoil Marinov" <stoil_mari...@hotmail.com> wrote in message
news:2tt4plF...@uni-berlin.de...

Will

unread,
Oct 23, 2004, 2:25:50 AM10/23/04
to
Unfortunately it didn't work , what am I doing wrong?

"Stoil Marinov" <stoil_mari...@hotmail.com> wrote in message
news:2tt4plF...@uni-berlin.de...
>

Norm Cook

unread,
Oct 23, 2004, 9:09:34 AM10/23/04
to
Use semicolons vice commas. Spaces don't matter.

"Will" <Wi...@bigpond.com> wrote in message

news:OPmed.36136$5O5....@news-server.bigpond.net.au...

Bob Butler

unread,
Oct 23, 2004, 9:13:46 AM10/23/04
to
"Will" <Wi...@bigpond.com> wrote in message news:<OPmed.36136$5O5....@news-server.bigpond.net.au>...

> Unfortunately it didn't work , what am I doing wrong?
> > Set the Filter property to the following string:
> > "Image files (*.jpg, *.gif, *.bmp)|*.jpg, *.gif, *.bmp|All files
> > (*.*)|*.*"

The spaces are not needed after the commas but this code works for me:

With CommonDialog1
.Filter = "Image files (*.jpg,*.gif,*.bmp)|" & _
"*.jpg,*.gif,*.bmp|All files (*.*)|*.*"
.ShowOpen
End With

Without seeing your code and without any indication of what is not
working for you it's hard to say what might be wrong.

Steve Gerrard

unread,
Oct 23, 2004, 1:29:15 PM10/23/04
to

"Will" <Wi...@bigpond.com> wrote in message
news:OPmed.36136$5O5....@news-server.bigpond.net.au...

| Unfortunately it didn't work , what am I doing wrong?


Although it is traditional to include the filter spec in the description
part of the filter, it is not actually necessary. There is really no
reason to tell the user that the filter for All Files is *.*, for
instance. It may be useful to tell them which image types you are
filtering for, but often it is just extra noise.

The text before the first | is just the text that will appear in the
File Type dropdown list, and can say anything you like. In this day and
age, you may want to include *.jpeg in your filter, since a lot of
images are now stored that way.

Private Sub Command1_Click()
With CommonDialog1
.Filter = "Ordinary Image Files|*.jpg;*.jpeg;*.bmp;*.gif|All
File Types|*.*"
.FilterIndex = 1
.ShowOpen
End With
End Sub

Will

unread,
Oct 24, 2004, 12:12:52 AM10/24/04
to
I tried all your suggestions but the only one that worked was the one with
the semi-colons between the file types:

Picture files (*.bmp *.gif *.jpg}|*.bmp;*.gif;*.jpg|All Files|*.*

thanks to everyone who tried to help.
PS. Why isn't this in MSDN info? It would have made life much easier.

"Will" <Wi...@bigpond.com> wrote in message

news:mBced.35665$5O5....@news-server.bigpond.net.au...

Frank Adam

unread,
Oct 24, 2004, 1:51:27 AM10/24/04
to
On Sun, 24 Oct 2004 04:12:52 GMT, "Will" <Wi...@bigpond.com> wrote:

>I tried all your suggestions but the only one that worked was the one with
>the semi-colons between the file types:
>
>Picture files (*.bmp *.gif *.jpg}|*.bmp;*.gif;*.jpg|All Files|*.*
>
>thanks to everyone who tried to help.
>PS. Why isn't this in MSDN info? It would have made life much easier.
>

Um.. it is.

<Quote>
Filter Property (CommonDialog)
<snip>
Remarks

A filter specifies the type of files that are displayed in the dialog
box's file list box. For example, selecting the filter *.txt displays
all text files.

Use this property to provide the user with a list of filters that can
be selected when the dialog box is displayed.

Use the pipe ( | ) symbol (ASCII 124) to separate the description and
filter values. Don't include spaces before or after the pipe symbol,
because these spaces will be displayed with the description and filter
values.

The following code shows an example of a filter that enables the user
to select text files or graphic files that include bitmaps and icons:

Text (*.txt)|*.txt|Pictures (*.bmp;*.ico)|*.bmp;*.ico

When you specify more than one filter for a dialog box, use the
FilterIndex property to determine which filter is displayed as the
default.
</Q>


--

Regards, Frank

0 new messages