Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / April 2006

Tip: Looking for answers? Try searching our database.

Files Disappear When Changing Filter in OpenFileDialog

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
marcus.kwok@gmail.com - 28 Feb 2006 19:41 GMT
I am having a weird problem and I have can't figure out why it is
happening.  I create an OpenFileDialog and set a filename filter.  When
the dialog first opens, the filter works correctly, and only the files
I want to see appear in the file list box.  When I change the filter to
one of the other filters, all the files in the list disappear.  If I
then manually type a filter into the "Filename" textbox, then the files
appear and the filter changes to the appropriate one.  I am confident
that my code is correct, because when I paste it into a test program
the filter works exactly as expected (the file list updates as soon as
I select a different filter).

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?
marcus.kwok@gmail.com - 28 Feb 2006 20:18 GMT
> I am having a weird problem and I have can't figure out why it is
> happening.  I create an OpenFileDialog and set a filename filter.  When
[quoted text clipped - 6 lines]
> the filter works exactly as expected (the file list updates as soon as
> I select a different filter).

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 ...
Marcus Kwok - 07 Mar 2006 22:51 GMT
> I am having a weird problem and I have can't figure out why it is
> happening.  I create an OpenFileDialog and set a filename filter.  When
> the dialog first opens, the filter works correctly, and only the files
> I want to see appear in the file list box.  When I change the filter to
> one of the other filters, all the files in the list disappear.

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?

Signature

Marcus Kwok

Marcus Kwok - 09 Mar 2006 15:31 GMT
>> I am having a weird problem and I have can't figure out why it is
>> happening.  I create an OpenFileDialog and set a filename filter.  When
[quoted text clipped - 39 lines]
> Can anybody else confirm this as a bug?  Or did I not do something
> properly, like wrap the native class somehow?

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?

Signature

Marcus Kwok

Marcus Kwok - 04 Apr 2006 19:35 GMT
>> I am having a weird problem and I have can't figure out why it is
>> happening.  I create an OpenFileDialog and set a filename filter.  When
[quoted text clipped - 39 lines]
> Can anybody else confirm this as a bug?  Or did I not do something
> properly, like wrap the native class somehow?

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.

Signature

Marcus Kwok

kael.cc@gmail.com - 12 Apr 2006 05:42 GMT
I'm also seeing this behavior just using the simple C# code:

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?
Marcus Kwok - 12 Apr 2006 14:32 GMT
> I'm also seeing this behavior just using the simple C# code:
>
[quoted text clipped - 4 lines]
> 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).

Signature

Marcus Kwok

V.Shiryaev - 17 Apr 2006 05:52 GMT
OpenFileDialog don't work with [MTAThread] attribute!

// 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();
}
}


Marcus Kwok - 17 Apr 2006 17:28 GMT
> OpenFileDialog don't work with [MTAThread] attribute!
>
[quoted text clipped - 24 lines]
> }
> }

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...).

Signature

Marcus Kwok
Replace 'invalid' with 'net' to reply


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.