FileDialog.Filter プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
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()
注釈
どちらかnull
Emptyの場合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 つの 拡張子 で記述する必要があります。 複数の 拡張機能 を使用する場合は、各 拡張機能 をセミコロン (";") で区切る必要があります。 次に例を示します。
"*.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|*.*
フィルターに含まれる各ファイルの種類は、次の図に示すように、[ファイル の種類] ドロップダウン リスト OpenFileDialog に SaveFileDialog個別の項目として追加されます。
ユーザーは、この一覧からファイルの種類を選択してフィルター処理できます。 既定では、リスト内の最初の項目 (たとえば、最初のファイルの種類) は、表示されるときにOpenFileDialogSaveFileDialog選択されます。 別のファイルの種類を選択するように指定するには、プロパティを FilterIndex 表示する前に OpenFileDialog 、または SaveFileDialog (呼び出して ShowDialog) 設定します。