SaveFileDialog

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I am programmatically creating a System.Windows.Forms.SaveFileDialog.
Everything works fine, however, I want to be able to detect when somebody
changes the filter property. Basically, I want to know when the file
extension is changed by the user so that I can automatically update the
filename property to have this extension at the end of the filename.
However, I can't seem to find some type of onfilterchange event to handle
this.

Does anybody have any ideas?

Thanks,
-- John
 
Hi John,

You should not need to detect a change in the filter property. Instead,
once the dialog is closed, take a look at the FileName property of the
SaveFileDialog, and then parse it for the extension you want. You can work
with that.


Here is a crude example:

Dim s As New SaveFileDialog

s.Filter = "Text Files (*.txt)|*.txt|Rich Text Format (*.rtf)|*.rtf|All
Files (*.*)|*.*"

Dim dr As System.Windows.Forms.DialogResult = s.ShowDialog

If dr = DialogResult.OK Then

Dim strExtension As String

strExtension = s.FileName.Substring(s.FileName.LastIndexOf(Char.Parse("."))
+ 1)

MessageBox.Show(strExtension)



End If


HTH,
Altaf
 
The SaveFileDialog does not have this feature unless you are ready to dig
real deep using window subclassing, p/invoke,etc.

Another option is to try using 3rd party controls which mimic the explorer
UI at http://www.ssware.com
 
Thanks guys. I thought I was going to have to do something like this. It
just seems a little crazy to have to p/invoke, (The SaveFileDialog class
won't let me inherit from it), or do some other crazy thing when all I want
is something like an OnFilterChange event.

Oh well. I appreciate the help.

Thanks again,
-- John
 
Back
Top