Search code examples
.netopenfiledialog

How can I avoid showing extensions on one Filter option in OpenFileDialog?


In addition to a list of supported file formats, I want to have a catch-all of "All Supported Files". I want the extensions to be displayed for the individual formats, but not for the catch-all. I thought this would do it:

    const string OpenFileFilters = "AAA Files (*.aaa)|*.aaa|" +
                           "BBB Files (*.bbb)|*.bbb|" +
                           "CCC Files (*.ccc)|*.ccc|" +
                           "DDD Files (*.ddd)|*.ddd|" +
                           "EEE Files (*.eee)|*.eee|" +
                           "FFF Files (*.fff)|*.fff|" +
                           "GGG Files (*.ggg)|*.ggg|" +
                           "HHH Files (*.hhh)|*.hhh|" +
                           "III Files (*.iii)|*.iii|" +
                           "All Supported Files |*.aaa;*.bbb;*.ccc;*.ddd;*.eee;*.fff;*.ggg;*.hhh;*.iii";

    var dialog = new OpenFileDialog
    {
        InitialDirectory = FileUtilites.ValidateInitialDirectory(initialDirectory),
        Filter = OpenFileFilters,
        FilterIndex = Settings.Default.OpenFileFilter,
        Multiselect = true
    };

    var result = dialog.ShowDialog();

But it gives me this:

OpenFileDialog extensions

Is there some way to specify the Filter string so that it will not include the long list of extensions on that last option?


Solution

  • I ended up using

    const string OpenFileFilters = "AAA Files (*.aaa)|*.aaa|" +
                           "BBB Files (*.bbb)|*.bbb|" +
                           "CCC Files (*.ccc)|*.ccc|" +
                           "DDD Files (*.ddd)|*.ddd|" +
                           "EEE Files (*.eee)|*.eee|" +
                           "FFF Files (*.fff)|*.fff|" +
                           "GGG Files (*.ggg)|*.ggg|" +
                           "HHH Files (*.hhh)|*.hhh|" +
                           "III Files (*.iii)|*.iii|" +
                           "All Supported Files (*.*)|*.aaa;*.bbb;*.ccc;*.ddd;*.eee;*.fff;*.ggg;*.hhh;*.iii";
    

    It shows (*.*) in the combo box, which is a lie, but it's a white lie.