Click here to Skip to main content
Licence CPOL
First Posted 22 Jul 2008
Views 40,050
Downloads 1,341
Bookmarked 23 times

SelectDialog - A Multiple File and Folder Select Dialog

By Hojjat Bohlooli | 26 Dec 2008
A multi select files and folders browse window
4 votes, 16.7%
1
4 votes, 16.7%
2
3 votes, 12.5%
3
5 votes, 20.8%
4
8 votes, 33.3%
5
3.21/5 - 24 votes
μ 3.25, σa 2.66 [?]
SelectDlg.jpg

Introduction

What's a Problem?

It has probably happened that you need a dialog like CFileDialog (MFC) that allows you to select some items together. I do not mean multi select file feature but multi select files and folders.

If you search MSDN and the internet for libraries which do that for you, maybe the best things you would find are CFileDialog for selecting single or multiple files and SHBrowseForFolder API for selecting a single folder.
So the problem is that you need a utility that makes it possible to select every browsable thing.

What Should We Do To Overcome the Problem?

If you want to have a single class using it you can select a file or a folder or some files or some folders or a mixture of them. I searched for such a utility but found nothing. So I decided to provide it and the best solution that I found was changing CFileDialog to do what I need.

Solution

CSelectDialog is a class that is inherited from CFileDialog and makes it possible for you to browse your computer or network and select a mixture of files and folders. For my convenience (as implementer) and user, I add a member of type CStringArray to the class to keep selected items after dialog returns IDOK.

Difference of CSelectDialog and CFileDialog

  1. Their user interface has some differences (You can see it in sample image in Vista.)
  2. OnInitDone, OnFolderChange, OnFileNameOK and WndProc functions of CFileDialog are overridden in CSelectDialog.

Using the Code

Use of CSelectDialog is similar to CFileDialog. Simply define a variable of type CSelectDialog and DoModal it. After user clicks the OK button, you can access the full path of selected items via m_lstSelectedItems member. A code snippet that does this work is shown below:

    CSelectDialog ofd(TRUE, _T("*.*"), NULL,
            OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT,
            _T("All files and folders(*.*)|*.*||") );

    if( ofd.DoModal() != IDOK )
        return;

    for( int i=0; i<ofd.m_SelectedItemList.GetCount(); i++ )
        m_lstSelectedItems.AddString( ofd.m_SelectedItemList[i] );

Some Notes

  1. If you want to disable multi select, you should make a change in CSelectDialog constructor.

  2. If you want to hide a combobox and its label below select dialog, you should uncomment 2 lines below in OnInitDone function:

        ...
        //HideControl(cmb13);
        //HideControl(stc3);
        ...
  3. For prevention of exception in XP SP3, you should comment all lines containing cmb13 in OnInitDone function.

Points of Interest

When I searched the Internet, nobody provided such a browse dialog with this feature.

History

  • Version 1.0 July 2008: First version of SelectDialog

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Hojjat Bohlooli

Other

Iran (Islamic Republic Of) Iran (Islamic Republic Of)

Member
حجت اله بهلولی
متولد 18 بهمن 1360 اصفهان
مدرک کارشناسی ارشد مهندسی کامپیوتر - نرم افزار
 
Hojjat Bohlooli
I was born in 7 Feb 1982, Isfahan Iran
Bachelor of science in Computer Science from Yazd university
Master of science in Software Engineering from university of Isfahan

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalcompiles using Visual Studio 2010 on Windows Server 2008 64-bit PinmemberRedDK8:50 23 May '11  
QuestionWindows 7 and VS2008 - not working !? PinmemberMiguelit023:56 21 Feb '10  
AnswerRe: Windows 7 and VS2008 - not working !? PinmemberNic Wilson14:40 30 Jun '10  
GeneralRe: Windows 7 and VS2008 - not working !? PinmemberHojjat Bohlooli3:55 1 Jul '10  
QuestionWould this be possible in C#? PinmemberTony Horray17:07 1 Feb '10  
AnswerRe: Would this be possible in C#? PinmemberMember 773664412:12 3 Apr '11  
GeneralWhy is the last selected file stored at address zero (in the m_lstSelectedItems[0] ) Pinmemberjtchangvit4:53 10 Nov '09  
GeneralRe: Why is the last selected file stored at address zero (in the m_lstSelectedItems[0] ) PinmemberHojjat Bohlooli5:02 12 Nov '09  
GeneralRe: Why is the last selected file stored at address zero (in the m_lstSelectedItems[0] ) PinmemberHojjat Bohlooli3:01 15 Nov '09  
GeneralBug with hidden file extensions Pinmemberpaste20003:07 9 Apr '09  
GeneralVS2008 and Vista Pinmemberpavritch20:48 12 Jan '09  
GeneralRe: VS2008 and Vista PinmemberNagender3:30 2 May '09  
GeneralRe: VS2008 and Vista Pinmembermark gooding1:34 18 Sep '09  
AnswerRe: VS2008 and Vista PinmemberMiguelit015:45 11 Aug '10  
GeneralMy vote of 1 PinmemberRob Graham9:49 26 Dec '08  
GeneralRe: My vote of 1 PinmemberJohannes P. Hansen23:13 30 Jun '09  
GeneralRe: My vote of 1 PinmemberHojjat Bohlooli3:51 1 Jul '09  
GeneralRe: My vote of 1 PinmemberJohannes P. Hansen3:01 2 Jul '09  
GeneralRe: My vote of 1 PinmemberHojjat Bohlooli3:59 2 Jul '09  
GeneralRe: My vote of 1 PinmemberJohannes P. Hansen4:21 2 Jul '09  
GeneralRe: My vote of 1 PinmemberHojjat Bohlooli9:08 3 Jul '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120209.1 | Last Updated 26 Dec 2008
Article Copyright 2008 by Hojjat Bohlooli
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid