CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2010
    Posts
    6

    File Filter List

    Hi all,

    I am trying to make a file/drive/folder directory interface with VB. It is all working except the only thing i can't manage to make it do is to filter on more than one file type.
    I want to be able to filter on BMP and TIF files, i have the following code:

    filterList.AddItem "*.TIF; *.BMP"

    filterList.SelText = filterList.List(0)

    'Apply the file type choosen to the file list displayed
    filDialog.Pattern = filterList.Text

    The filterList is the list box with the file type extensions and the filDialog is the list box with the files.

    It only filters on the first file type, so in this case TIF (no BMP), even if you swap them it only filters on the first file type.

    Can anyone shed some light on this? i have seen other examples (limited) on the web and it says to do as ive done, why doesn't mine work? is there a project reference i have to add in?

    Thanks,

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: File Filter List

    You need to use OR (= |)

    Here's 3 options:

    ALL | TXT | BAT


    Code:
    Option Explicit
    
    ' cdlCFPrinterFonts &H2
    
    ' Save File Options
    '&H2 - Forces a warning before overwriting a file
    '&H8 - Stops default directory from changing
    '&H200 - more than one file can be selected.
    '&H1000 - This makes it so the file must exist.
    '&H2000 - This warns the user before creating a new file.
    
    Private Sub cmdOpen_Click()
      ' CancelError is True.
       On Error GoTo ErrHandler
       CommonDialog1.InitDir = App.Path
       ' Set Flags
        CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNLongNames
       ' Set filters.
       CommonDialog1.Filter = "All Files (*.*)|*.*|Text" & _
          "Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
       '  CommonDialog1.Filter = "AutoForm Files (*.doc) (*.rtf)|*.doc;*.rtf|All " & _
              "Files (*.*)|*.*"
       
       ' Specify default filter.
       CommonDialog1.FilterIndex = 2 ' Default to TEXT
       ' Display the Open dialog box.
       CommonDialog1.ShowOpen
       ' Call the open file procedure.
     '  OpenFile (CommonDialog1.FileName)
       Debug.Print CommonDialog1.FileName
       Exit Sub
    
    ErrHandler:
    ' User pressed Cancel button.
       Exit Sub
    
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2009
    Posts
    394

    Re: File Filter List

    Pssst, hey Dave,... "The filterList is the list box with the file type extensions and the filDialog is the list box with the files." makes me think OP is using the FileListBox control and then this "filDialog.Pattern = filterList.Text" confirms it so it would be...
    Code:
    filterList.Text = "*.bmp;*.tif" 'no spaces between ; & *
    
    filDialog.Pattern = filterList.Text


    Good Luck

  4. #4
    Join Date
    Dec 2001
    Posts
    6,332

    Re: File Filter List

    I think vb5prgrmr saw the problem. That is, there shouldn't be any spaces between the file types.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured