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? 8 5933 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 ... 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
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
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
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? 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
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
------------------------------------------------------------------------
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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?...
|
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...
|
by: iwdu15 |
last post by:
how can i open a file i saved and place the info into different text boxes?
|
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...
|
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
|
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...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
| |