473,770 Members | 5,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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->InitialDirecto ry = S"input";
dlg->Filter = S"Transmitte r files (xmtr*.dat)|xmt r*.dat|DAT files
(*.dat)|*.dat|A ll files (*.*)|*.*";
if (dlg->ShowDialog() == DialogResult::O K) {
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|A ll files (*.*)|*.*";

and I get the same result.

Has anybody seen this issue before?

Feb 28 '06 #1
8 6097
ma*********@gma il.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*********@gma il.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|A ll 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******@gehen nom.net.invalid > wrote:
ma*********@gma il.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|A ll 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******@gehen nom.net.invalid > wrote:
ma*********@gma il.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|A ll 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.c om 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.codeco mments.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::Threadi ng::Thread::Cur rentThread->ApartmentSta te = System::Threadi ng::ApartmentSt ate::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
8263
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 OpenFileDialog(); MyDialog.Multiselect = true ; MyDialog.Filter = "WAVE files (*.wav)|*.wav|All files (*.*)|*.*" ; MyDialog.RestoreDirectory = true ;
2
3791
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 done? -- Steve
1
4436
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 f(openFileDialog.ShowDialog() == DialogResult.OK) { ... } Now I discover that there is a hardcoded limit of 200 files.
3
1996
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? How? -------------------------------- From: vishpala kadam vishpala_kadam@yahoo.com ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/)
0
373
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 populated with file names from the OpenFileDialog method (see below). The problem is that if you select, say three files in the Open File dialogue box, the listbox is populated with three of the same file rather than three different files.
16
2207
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
4
3620
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 selected no db files are listed in the OpenFileDialog box.... ------------------------------------- Private Sub btnDatabase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDatabase.Click Dim objOpenFileDialog As New...
2
2669
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
1138
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 Open.ShowDialog(). What I want to do is filter the open file so that only text files (*.txt) can be opened. The project I am working with has two projects and one solution. The main project uses Open as the variable for the Open file dialog. the The...
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10231
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8887
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6679
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5452
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.