如何避免在OpenFileDialog中的一个Filter选项上显示扩展名?

时间:2017-11-15 00:18:57

标签: .net openfiledialog

除了支持的文件格式列表之外,我还想拥有一个“全部支持的文件”。我希望为各种格式显示扩展名,但不是为了全面显示。我以为会这样做:

    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();

但它给了我这个:

OpenFileDialog extensions

有没有办法指定Filter字符串,以便它不包含最后一个选项的长扩展列表?

1 个答案:

答案 0 :(得分:0)

我最终使用

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";

它在组合框中显示(*.*),这是一个谎言,但它是一个白色谎言。