judico
asked on
File filter in managed Visual C++ .NET
I’ve been trying to apply in managed VC++.NET the file filter which I use in VB.NET and which works fine there, supposing that in Visual Studio .NET those filters should not be language specific. Thus, in the Properties of the openFileDialog of a VC++.NET form, in the section Filter, I type in:
Document Files(*.txt)|*.txt
But it doesn’t seem to filter out the .txt files when I open the dialog.
Aslo, I’d like to have the extension .txt automatically attached to the file name when I type it in the saveFileDialog. How is all this done in managed Visual C++ .NET?
Document Files(*.txt)|*.txt
But it doesn’t seem to filter out the .txt files when I open the dialog.
Aslo, I’d like to have the extension .txt automatically attached to the file name when I type it in the saveFileDialog. How is all this done in managed Visual C++ .NET?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The 'if' statement is to test whether the dialog was cancelled or not - the test is true if the dialog was not cancelled. The line inside the block was just a test line to print out the selected file name.
As for setting properties, I (almost) always code by hand, so I don't know why setting properties of the dialog would not work. If I get some time I'll try it and see if it works.
As for setting properties, I (almost) always code by hand, so I don't know why setting properties of the dialog would not work. If I get some time I'll try it and see if it works.
ASKER
OK, thanks again ...
ASKER
Since I don't see the ponts for answering this question increased I asked for increase in the Community Support:
https://www.experts-exchange.com/questions/21103692/Please-increase-the-number-of-points-for-drichards.html
https://www.experts-exchange.com/questions/21103692/Please-increase-the-number-of-points-for-drichards.html
ASKER
Just, out of curiosity, how can one have other file types listed in the drop-down menu of the openFileDialog?
The filter is a concatenation of string pairs where each string is separated by '|'. So to get multiple filter selections, just keep adding:
ofd->Filter = S"Document Files (*.txt)|*.txt|Word Files (*.doc)|*.doc";
will give you two selections - "Document Files (*.txt)" and "Word Files (*.doc)". You could keep going and tack on "|Excel Files (*.xls)|*.xls", etc. You can also do multiple extensions at once by using ';' as a separator in the extension part of the pair:
ofd->Filter = S"Document Files (*.txt)|*.txt|Word Files (*.doc,*.zip)|*.doc;*zip";
ofd->Filter = S"Document Files (*.txt)|*.txt|Word Files (*.doc)|*.doc";
will give you two selections - "Document Files (*.txt)" and "Word Files (*.doc)". You could keep going and tack on "|Excel Files (*.xls)|*.xls", etc. You can also do multiple extensions at once by using ';' as a separator in the extension part of the pair:
ofd->Filter = S"Document Files (*.txt)|*.txt|Word Files (*.doc,*.zip)|*.doc;*zip";
ASKER
Thanks a lot. I would appreciate it if you could take a look at:
https://www.experts-exchange.com/questions/21102023/A-question-to-mrdtn-How-does-one-close-the-port-of-the-multimeter.html
Thanks in advance.
https://www.experts-exchange.com/questions/21102023/A-question-to-mrdtn-How-does-one-close-the-port-of-the-multimeter.html
Thanks in advance.
ASKER
Netminder,
Thank you ... I just increased the number of points ... Please let me know if there are other problems.
judico
Thank you ... I just increased the number of points ... Please let me know if there are other problems.
judico
ASKER
if ( ofd->ShowDialog() == System::Windows::Forms::Di
{
System::Console::WriteLine
}
Is there any specific reason why it should be there? Also, I 'm still puzzled why wouldn't filtering work in managed VC++ .NET when set through the Properties of the form? I'm just curious and it has no bearing on your excellent answer. I wonder if I should ignore these Properties that accompany the forms and should learn to do everything through code?
P.S. I increased your points to 250. Please let me know if you have problems in receiving the increased points.