Open Dialog Filter Doesn't Work

  • Thread starter Thread starter Brian P. Hammer
  • Start date Start date
B

Brian P. Hammer

All,

I have an open file dialog on one of my forms. Everything works great except the filter. I am trying to hide all files that do not have an extension of cap but any file extension shows up. Any ideas with the code below?

Dim myOpenFileDialog As New OpenFileDialog()
Try
With myOpenFileDialog
.CheckFileExists = True
.CheckPathExists = True
.DefaultExt = "cap"
.DereferenceLinks = True
.InitialDirectory = DocsPath & "\CACE"
.Filter = "CACE files (*.cap)|"
.Multiselect = False
.RestoreDirectory = True
.ShowHelp = True
.ShowReadOnly = False
.Title = "Select a CACE file to open"
.ValidateNames = True
If .ShowDialog() = DialogResult.OK Then
FileName = .FileName
dsAircraft = ReadInData()
PopulateTree()
BindData()
ShowMenus(True)
Me.mnuSave.Enabled = False
Me.tbSave.Enabled = False
Me.tmrDirty.Interval = 500
Me.tmrDirty.Enabled = True
MakeRecordDirty(False)
HasLoaded = True
PerformCalculations()
LoadChartData()
Else
Exit Sub
End If
End With
 
Brian,
You specified the filter incorrectly.

.Filter = "CACE files (*.cap)|"

needs to be:

.Filter = "CACE files (*.cap)|*.cap"

The first part of the filter is the description (what the user sees), the
second part of the filter is the pattern (the actual filter applied to the
files).

Hope this helps
Jay

All,

I have an open file dialog on one of my forms. Everything works great
except the filter. I am trying to hide all files that do not have an
extension of cap but any file extension shows up. Any ideas with the code
below?

Dim myOpenFileDialog As New OpenFileDialog()
Try
With myOpenFileDialog
.CheckFileExists = True
.CheckPathExists = True
.DefaultExt = "cap"
.DereferenceLinks = True
.InitialDirectory = DocsPath & "\CACE"
.Filter = "CACE files (*.cap)|"
.Multiselect = False
.RestoreDirectory = True
.ShowHelp = True
.ShowReadOnly = False
.Title = "Select a CACE file to open"
.ValidateNames = True
If .ShowDialog() = DialogResult.OK Then
FileName = .FileName
dsAircraft = ReadInData()
PopulateTree()
BindData()
ShowMenus(True)
Me.mnuSave.Enabled = False
Me.tbSave.Enabled = False
Me.tmrDirty.Interval = 500
Me.tmrDirty.Enabled = True
MakeRecordDirty(False)
HasLoaded = True
PerformCalculations()
LoadChartData()
Else
Exit Sub
End If
End With
 
Back
Top