Reputation: 684
I'm trying to utilize one of CFileDialog's parameter OFN_ALLOWMULTISELECT to allow user to select multiple file paths with ctrl+click. However, it doesn't fulfill my goal which is to also make selections from other folders without opening and closing the dialog again. I've searched the internet for some solutions but seems like that's just how OFN_ALLOWMULTISELECT works.
This code below is what works fine, but only for selecting within the same folder:
CFileDialog fileDialog( TRUE, NULL, NULL,
/*OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER |*/ OFN_ALLOWMULTISELECT,
NULL, this);
if (fileDialog.DoModal() == IDOK)
{
//Multi-selection
CString strPaths;
CComPtr<IFileOpenDialog> piod = fileDialog.GetIFileOpenDialog();
ASSERT( piod );
CComPtr<IShellItemArray> pResults;
if( SUCCEEDED( piod->GetResults( &pResults ) ) )
{
DWORD count = 0; pResults->GetCount( &count );
for( DWORD i = 0; i < count; ++i )
{
CComPtr<IShellItem> pItem;
if( SUCCEEDED( pResults->GetItemAt( i, &pItem ) ) )
{
CComHeapPtr<wchar_t> pPath;
if( SUCCEEDED( pItem->GetDisplayName( SIGDN_FILESYSPATH, &pPath ) ) )
{
if( !strPaths.IsEmpty() )
strPaths += L"\n";
strPaths += pPath;
}
}
}
}
m_strAddedFilePaths = strPaths;
//UpdateData(FALSE);
}
[Graphical explanation]:
For example, I select two files here.
As I navigate to a different folder and select a new file, the previous selection would be gone
So the question is how do I retain my previous selections?
Is this considered a limitation in this class or is there a way to do it?
Upvotes: 1
Views: 385
Reputation: 11311
You can customize CFileDialog
as described here: MFC extending CFileDialog by adding a list control where you would accumulate all the selected files from different folders. You can add your "is it modified?", "newly added", etc. there, too.
Upvotes: 1