473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Files Disappear When Changing Filter in OpenFileDialog

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?

Feb 28 '06 #1
8 6038
ma*********@gmail.com wrote:
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).


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

Feb 28 '06 #2
ma*********@gmail.com wrote:
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?

--
Marcus Kwok
Mar 7 '06 #3
Marcus Kwok <ri******@gehennom.net.invalid> wrote:
ma*********@gmail.com wrote:
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?


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
Mar 9 '06 #4
Marcus Kwok <ri******@gehennom.net.invalid> wrote:
ma*********@gmail.com wrote:
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?


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
Apr 4 '06 #5
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?

Apr 12 '06 #6
ka*****@gmail.com wrote:
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?


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
Apr 12 '06 #7

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

--
V.Shiryaev
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Apr 17 '06 #8
V.Shiryaev <V.***************@mail.codecomments.com> wrote:
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();
}
}


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
Apr 17 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Wim | last post by:
I'm trying to add files with a OpenFileDialog to a listview. This is what I've come up with sofar: protected void ButAddClick(object sender, System.EventArgs e) { OpenFileDialog MyDialog = new...
2
by: Steve Teeples | last post by:
I am using the Filter property within OpenFileDialog. I understand how to filter files with extensions, but this time I need to filter files without extensions. Can someone tell me how this is...
1
by: Olaf Baeyens | last post by:
In .NET v1.1 I am trying to select multiple files using OpenFileDialog like this OpenFileDialog openFileDialog=new OpenFileDialog(); openFileDialog.Multiselect=true; i...
3
by: vishpala kadam via .NET 247 | last post by:
Hi, I am using <input type="file"> to upload files in my asp.net application. I want to set the filter so that user can view only .xls files once he/she clicks the Browse button. Is it possible?...
0
by: John | last post by:
Hi there, I'm just starting at VB.NET (all VB come to that), and have what's probably a very basic question: I have a form in Visual Studio 2003 that has a listbox that is meant to be...
16
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
4
by: Mike | last post by:
I need help understanding why the following code is not working correctly. When run, I can open .mdb files by changing the filter option to "All Files (*.*)" but while "Access Database (mdb.*)" is...
2
by: dermot | last post by:
hi, I'm opening a file dialog in a vb.net form. I want to show only files modified after a certain date. Is there anyway to filter for this? Thanks
3
by: Charlie Brookhart | last post by:
I have created a program that opens a file and counts words, characters, sentences, etc. I have not used the open file dialog control found in the VB ..NET 2003 toolbox. I instead have used...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.