FileDialog.Filter プロパティ

定義

OpenFileDialog または SaveFileDialog で表示されるファイルの種類を決定するフィルター文字列を取得または設定します。

public:
 property System::String ^ Filter { System::String ^ get(); void set(System::String ^ value); };
public string Filter { get; set; }
member this.Filter : string with get, set
Public Property Filter As String

プロパティ値

フィルターを格納している String。 既定値は Empty です。これは、フィルターが適用されず、すべてのファイルの種類が表示されることを意味します。

例外

フィルター文字列が無効です。

次の例では、 プロパティを使用して設定できるいくつかの種類のフィルター文字列を Filter 示します。

OpenFileDialog dlg = new OpenFileDialog();

// Show all files
dlg.Filter = string.Empty;

dlg.ShowDialog();
Dim dlg As New OpenFileDialog()

' Show all files
dlg.Filter = String.Empty

dlg.ShowDialog()
OpenFileDialog dlg = new OpenFileDialog();

// Show all files
dlg.Filter = null;

dlg.ShowDialog();
Dim dlg As New OpenFileDialog()

' Show all files
dlg.Filter = Nothing

dlg.ShowDialog()
OpenFileDialog dlg = new OpenFileDialog();

// Filter by Word Documents
dlg.Filter = "Word Documents|*.doc";

dlg.ShowDialog();
Dim dlg As New OpenFileDialog()

' Filter by Word Documents
dlg.Filter = "Word Documents|*.doc"

dlg.ShowDialog()
OpenFileDialog dlg = new OpenFileDialog();

// Filter by Excel Worksheets
dlg.Filter = "Excel Worksheets|*.xls";

dlg.ShowDialog();
Dim dlg As New OpenFileDialog()

' Filter by Excel Worksheets
dlg.Filter = "Excel Worksheets|*.xls"

dlg.ShowDialog()
OpenFileDialog dlg = new OpenFileDialog();

// Filter by PowerPoint Presentations
dlg.Filter = "PowerPoint Presentations|*.ppt";

dlg.ShowDialog();
Dim dlg As New OpenFileDialog()

' Filter by PowerPoint Presentations
dlg.Filter = "PowerPoint Presentations|*.ppt"

dlg.ShowDialog()
OpenFileDialog dlg = new OpenFileDialog();

// Filter by Office Files
dlg.Filter = "Office Files|*.doc;*.xls;*.ppt";

dlg.ShowDialog();
Dim dlg As New OpenFileDialog()

' Filter by Office Files
dlg.Filter = "Office Files|*.doc;*.xls;*.ppt"

dlg.ShowDialog()
OpenFileDialog dlg = new OpenFileDialog();

// Filter by All Files
dlg.Filter = "All Files|*.*";

dlg.ShowDialog();
Dim dlg As New OpenFileDialog()

' Filter by All Files
dlg.Filter = "All Files|*.*"

dlg.ShowDialog()
OpenFileDialog dlg = new OpenFileDialog();

// Filter by Word Documents OR Excel Worksheets OR PowerPoint Presentations 
//           OR Office Files 
//           OR All Files
dlg.Filter = "Word Documents|*.doc|Excel Worksheets|*.xls|PowerPoint Presentations|*.ppt" +
             "|Office Files|*.doc;*.xls;*.ppt" +
             "|All Files|*.*";

dlg.ShowDialog();
Dim dlg As New OpenFileDialog()

' Filter by Word Documents OR Excel Worksheets OR PowerPoint Presentations 
'           OR Office Files 
'           OR All Files
dlg.Filter = "Word Documents|*.doc|Excel Worksheets|*.xls|PowerPoint Presentations|*.ppt" & "|Office Files|*.doc;*.xls;*.ppt" & "|All Files|*.*"

dlg.ShowDialog()

注釈

が または Emptynull場合Filterは、すべてのファイルが表示され、フォルダーは常に表示されます。

プロパティを設定することで、表示するファイルの種類のサブセットを Filter 指定できます。 各ファイルの種類は、次のような特定の種類のファイルを表すことができます。

  • ドキュメントのWord (*.doc)

  • Excel ワークシート (*.xls)

  • PowerPoint プレゼンテーション (*.ppt)

または、ファイルの種類は、次のような関連するファイルの種類のグループを表すことができます。

  • Office ファイル (*.doc、*.xls、*.ppt)

  • すべてのファイル (*.*)

表示されるファイルの種類のサブセットを指定するには、フィルター処理する 1 つ以上の種類のファイルを指定する文字列値 (フィルター文字列) を使用して プロパティを設定Filterします。 次に、フィルター文字列の予期される形式を示します。

FileType1[[|FileType2]...[|FileTypeN]]

次の形式を使用して、各ファイルの種類を記述します。

Label|Extension1[[;Extension2]...[;ExtensionN]]

Label パーツは、次のようなファイルの種類を記述する、人間が判読できる文字列値です。

  • "ドキュメントのWord"

  • "Excel ワークシート"

  • "PowerPoint プレゼンテーション"

  • "Office ファイル"

  • "すべてのファイル"

各ファイルの種類は、少なくとも 1 つの Extension で記述する必要があります。 複数の 拡張機能 を使用する場合、各 拡張機能 はセミコロン (";") で区切る必要があります。 次に例を示します。

  • "*.doc"

  • "*.xls;"

  • "*.ppt"

  • "*.doc;*.xls;*.ppt"

  • "*.*"

有効な Filter 文字列値の完全な例を次に示します。

  • Word Documents|*.doc

  • Excel Worksheets|*.xls

  • PowerPoint Presentations|*.ppt

  • Office Files|*.doc;*.xls;*.ppt

  • All Files|*.*

  • Word Documents|*.doc|Excel Worksheets|*.xls|PowerPoint Presentations|*.ppt|Office Files|*.doc;*.xls;*.ppt|All Files|*.*

フィルターに含まれる各ファイルの種類は、次の図に示すように、 または SaveFileDialogの [ファイルの種類] ドロップダウン リストにOpenFileDialog個別の項目として追加されます。

[開く] ダイアログ ボックスで FileDialog.Filter を使用する [開く] ダイアログ ボックス

ユーザーは、この一覧からファイルの種類を選択してフィルター処理できます。 既定では、 または SaveFileDialog が表示されるときにOpenFileDialog、リスト内の最初の項目 (最初のファイルの種類など) が選択されます。 別のファイルの種類を選択するように指定するには、 または SaveFileDialogFilterIndex表示する前に ( を呼び出ShowDialogして) プロパティをOpenFileDialog設定します。

適用対象

こちらもご覧ください