Solved

CFileDialog and Multiple File Types

Posted on 2008-06-17
7
1,004 Views
Last Modified: 2013-12-14
In my VC 6.0 app, I display a CFileDialog.  I simply want it to display all files with the following extensions, AT THE SAME TIME: ".txt", and ".xls".  I can get CFileDialog to display just the text files, or just the spreadsheet files, but I can't get it display both types at the same time.

Thanks, ahead of time.
0
Comment
Question by:clintonJ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 19

Expert Comment

by:alb66
ID: 21802469
You must use the following filter:

Text file (*.txt)|*.txt|Excel file (*.xls)|*.xls||
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 250 total points
ID: 21802477
Hi ClintonJ,

you just can seperate multiple extensions with a ;

I.e. use this filter string:

"Excel Files (*.txt;*.xls)|*.txt;*.xls|All files (*.*)|*.*||";


Hope that helps,

ZOPPO
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21802482
When you create it you can set the filter to be multiple types, using | as a separator, something like...

CFileDialog OpenDlg(false,NULL,NULL,0,_T("TXT Files (*.txt)|*.txt|XLS Files (*.xls)|*.xls"),NULL);
http://msdn.microsoft.com/en-us/library/wh5hz49d(VS.80).aspx

lpszFilter
A series of string pairs that specify filters you can apply to the file. If you specify file filters, only selected files will appear in the Files list box. See the Remarks section for more information on how to work with file filters
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:alb66
ID: 21802507
ZOPPO is right; I misunderstud the question.
0
 

Author Comment

by:clintonJ
ID: 21802571
OK, we're getting there.  The constructor for CFileDialog looks like this:

CFileDialog( BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL );

So, thanks to you, :) my lpszFilter parameter now looks like this:

 lpszFilter = "Data Files (*.txt;*.xls)|*.txt;*.xls|All files (*.*)|*.*||";

When the CFileDialog displays, the "Files of Type" textbox now displays the correct file extensions (.txt AND .xls).  

One small problem though: The only file names  that display are .txt files, even though I also have .xls files in the same folder.  Do I need to also adjust LPCTSTR lpszDefExt to get the excel file names to also display?

0
 
LVL 19

Assisted Solution

by:alb66
alb66 earned 250 total points
ID: 21802617
This works properli with VS2003:

      CFileDialog dlg( true, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
                                      "Data Files (*.txt;*.xls)|*.txt;*.xls|All files (*.*)|*.*||",
                                      NULL );
      dlg.DoModal();
0
 

Author Closing Comment

by:clintonJ
ID: 31467937
Thanks very much.  Perfecto!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adding items to a C# list incrementally 5 84
Can Live bindings change TGrid Cell Colour ? 1 64
maximize the sum of fractions 33 76
cmake and message 1 26
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question