Here is the code that I am using:
OpenFileDialog* dlg = new OpenFileDialog();
dlg->Title = S"Choose Transmitter file";
dlg->InitialDirectory = S"input";
dlg->Filter = S"Transmitter files (xmtr*.dat)|xmtr*.dat|DAT files
(*.dat)|*.dat|All files (*.*)|*.*";
if (dlg->ShowDialog() == DialogResult::OK) {
textbox_xmtr->Text = dlg->FileName;
}
I have also tried it with a filter that only restricts on file
extension, i.e.,
dlg->Filter = S"DAT files (*.dat)|*.dat|All files (*.*)|*.*";
and I get the same result.
Has anybody seen this issue before?
I should have mentioned that I am using VS .NET 2003. Also, I did
another test with interesting results.
If I change the filter, the files disappear. If I then browse to
another folder, then the filter is applied correctly. For example,
open dialog -> change filter -> files disappear -> click "parent
directory" button -> filter is applied and files are listed ->
double-click on original directory -> filter is still applied and files
are listed -> change filter again -> files disappear again ...
OK, I figured out how to reproduce this problem.
This is using Visual C++ .NET 2003 (Managed Extensions to C++, not
C++/CLI).
1. I created a new Visual C++ Windows Forms Application (.NET).
2. I added a button to this form.
3. I added an event handler for this button that consists of the
following:
OpenFileDialog* dlg = new OpenFileDialog;
dlg->Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
dlg->ShowDialog();
4. I added a native C++ file that consists of the following:
#include <iostream>
void f()
{
// Comment the following line to get correct behavior
std::cout << 0;
}
5. I turned off Precompiled Headers for the project. (not essential,
otherwise you need to add #include "stdafx.h" to the native file).
6. Compile and run (click the button then change the file filter).
Note that nowhere in the program did I actually call the function f().
It seems that its mere existence in the project is enough to mess this
up.
Can anybody else confirm this as a bug? Or did I not do something
properly, like wrap the native class somehow?
--
Marcus Kwok
Hmm, I gave the source code and pre-compiled executables to my colleague
and the issue does not occur on his system. However, I tried it on a
different system and I DO get the bug (with the exact same pre-compiled
binary). Does anybody have any idea of how I can track down the source
of this problem?
--
Marcus Kwok
Sorry to follow up to myself so many times, but I did find a workaround
to this problem that nobody else seems to have been able to reproduce.
If I set the project to "Not using managed extensions", but then only
enable it for the files that actually use them (plus add the appropriate
#using <mscorlib.dll>, #using <System.dll>, #using
<System.Windows.Forms.dll>, etc.), then the app behaves correctly.
I really wish this were documented somewhere, so I didn't have to waste
so much time hunting it down and figuring out the workaround. Of
course, I guess it would have helped if someone else were able to
reproduce the behavior I saw.
--
Marcus Kwok
OpenFileDialog d = new OpenFileDialog();
d.Filter="a (a*.*)|a*.*|b (b*.*)|b*.*";
d.ShowDialog();
This seems to obvious to be a bug. Could it be a system configuration
problem?
It's possible, since it happens on my computer but not my colleagues,
and by the lack of responses here, not on anyone else's (besides yours).
I thought that maybe because I have both VS .NET 2003 and VS 6.0 on my
same machine that there is some conflict, but the code is using .NET
constructs, so AFAIK the 6.0 stuff shouldn't conflict. Also, the issue
happens on another machine that only has VS .NET 2003 on it (no 6.0).
--
Marcus Kwok
// weird problem with file and directories,
// then changing filter.
public class main
{
*[MTAThread]*
static void Main()
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter="*.bmp (*.bmp)|*.bmp|*.jpg (*.jpg)|*.jpg";
openFileDialog.Title="Open File";
openFileDialog.ShowDialog();
}
}
// correct behavior
public class main
{
*[STAThread]*
static void Main()
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter="*.bmp (*.bmp)|*.bmp|*.jpg (*.jpg)|*.jpg";
openFileDialog.Title="Open File";
openFileDialog.ShowDialog();
}
}
--
V.Shiryaev
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------
I think the problem may be deeper than this, since in my sample project
I have
System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;
as the first line of _tWinMain().
(this is MC++ not C# but it should be the same...).
--
Marcus Kwok
Replace 'invalid' with 'net' to reply